[gcc r17-2233] gccrs: Fix ICE when trying to resolve const expr

Arthur Cohen via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:3541e0be7cab2af23dc45757015f2bcdda93f9dc

commit r17-2233-g3541e0be7cab2af23dc45757015f2bcdda93f9dc
Author: Philip Herron <[email protected]>
Date:   Wed Jun 24 16:28:11 2026 +0100

    gccrs: Fix ICE when trying to resolve const expr
    
    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 <[email protected]>

Diff:
---
 gcc/rust/backend/rust-compile-resolve-path.cc |  4 +++-
 gcc/testsuite/rust/compile/issue-4302.rs      | 12 ++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index d665df70f07e..d9225718b136 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -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
index 000000000000..2ba30551b2a9
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4302.rs
@@ -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
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.