From: jayant chauhan <[email protected]>
Fixes Rust-GCC#3910
gcc/rust/ChangeLog:
* backend/rust-compile-item.cc (CompileItem::visit): Do not insert
const_expr into the context if it is an error_mark_node.
* backend/rust-compile-implitem.cc (CompileTraitItem::visit): Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3910.rs: New test.
Signed-off-by: jayant chauhan <[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/f1e56c467f24fe98ee74120ec862ca12a0fb00fc
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4438
gcc/rust/backend/rust-compile-implitem.cc | 8 ++++++--
gcc/rust/backend/rust-compile-item.cc | 7 +++++--
gcc/testsuite/rust/compile/issue-3910.rs | 14 ++++++++++++++
3 files changed, 25 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-3910.rs
diff --git a/gcc/rust/backend/rust-compile-implitem.cc
b/gcc/rust/backend/rust-compile-implitem.cc
index f4adaa2dd..c94f439e1 100644
--- a/gcc/rust/backend/rust-compile-implitem.cc
+++ b/gcc/rust/backend/rust-compile-implitem.cc
@@ -44,8 +44,12 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
resolved_type, canonical_path, const_value_expr,
constant.get_locus (),
const_value_expr.get_locus ());
- ctx->push_const (const_expr);
- ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);
+ if (const_expr != error_mark_node)
+ {
+ ctx->push_const (const_expr);
+ ctx->insert_const_decl (constant.get_mappings ().get_hirid (),
+ const_expr);
+ }
reference = const_expr;
}
diff --git a/gcc/rust/backend/rust-compile-item.cc
b/gcc/rust/backend/rust-compile-item.cc
index 28694361b..f9b003cf5 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -129,8 +129,11 @@ CompileItem::visit (HIR::ConstantItem &constant)
const_value_expr.get_locus ());
ctx->pop_const_context ();
- ctx->push_const (const_expr);
- ctx->insert_const_decl (mappings.get_hirid (), const_expr);
+ if (const_expr != error_mark_node)
+ {
+ ctx->push_const (const_expr);
+ ctx->insert_const_decl (mappings.get_hirid (), const_expr);
+ }
reference = const_expr;
}
diff --git a/gcc/testsuite/rust/compile/issue-3910.rs
b/gcc/testsuite/rust/compile/issue-3910.rs
new file mode 100644
index 000000000..57022943e
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3910.rs
@@ -0,0 +1,14 @@
+#![feature(no_core)]
+#![no_core]
+
+struct B<const M: u32> {}
+
+impl<const M: u32> B<M> {
+ const M: u32 = M;
+}
+
+struct C;
+
+impl<const M: u32> C { // { dg-error "unconstrained type parameter" }
+ const USE_M: u32 = M;
+}
\ No newline at end of file
base-commit: 4b5342014c474e63ddba03ecebc2828e017d691f
--
2.53.0