]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix ICE when trying to resolve const expr
authorPhilip Herron <herron.philip@googlemail.com>
Wed, 24 Jun 2026 15:28:11 +0000 (16:28 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 8 Jul 2026 15:22:46 +0000 (17:22 +0200)
We cannot resolve N + 1 a this stage since N has no default and is const
generic, rustc makes a more precise error diag here but our one is
completely fine for now.

Fixes Rust-GCC#4302

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc: use error_mark_node

gcc/testsuite/ChangeLog:

* rust/compile/issue-4302.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/backend/rust-compile-resolve-path.cc
gcc/testsuite/rust/compile/issue-4302.rs [new file with mode: 0644]

index d665df70f07e57e969e4790dba41196a3edef7b9..d9225718b136aa928f45ff05463325344cede720 100644 (file)
@@ -194,7 +194,9 @@ ResolvePathRef::resolve_with_node_id (
       auto d = lookup->destructure ();
       rust_assert (d->get_kind () == TyTy::TypeKind::CONST);
       auto c = d->as_const_type ();
-      rust_assert (c->const_kind () == TyTy::BaseConstType::ConstKind::Value);
+      if (c->const_kind () != TyTy::BaseConstType::ConstKind::Value)
+       return error_mark_node;
+
       auto val = static_cast<TyTy::ConstValueType *> (c);
       return val->get_value ();
     }
diff --git a/gcc/testsuite/rust/compile/issue-4302.rs b/gcc/testsuite/rust/compile/issue-4302.rs
new file mode 100644 (file)
index 0000000..2ba3055
--- /dev/null
@@ -0,0 +1,12 @@
+#![feature(no_core, intrinsics, staged_api, lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+pub struct Foo<const N: usize>;
+
+pub fn foo<const N: usize>() -> Foo<{ N + 1 }> {
+    // { dg-error "failed to resolve const expression" "" { target *-*-* } .-1 }
+    Foo
+}