From: Philip Herron <[email protected]>

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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/696cb485cfa9969c952d6765889d82ed548ca15c

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4607

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

diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc 
b/gcc/rust/backend/rust-compile-resolve-path.cc
index d665df70f..d9225718b 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 000000000..2ba30551b
--- /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
+}
-- 
2.54.0

Reply via email to