Skip to content

Commit 532c867

Browse files
committed
backend: Prevent error_mark_node from leaking into const context
Fixes #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 <0001jayant@gmail.com>
1 parent 1c6d3bf commit 532c867

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

gcc/rust/backend/rust-compile-implitem.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
4444
resolved_type, canonical_path, const_value_expr,
4545
constant.get_locus (),
4646
const_value_expr.get_locus ());
47-
ctx->push_const (const_expr);
48-
ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);
47+
if (const_expr != error_mark_node)
48+
{
49+
ctx->push_const (const_expr);
50+
ctx->insert_const_decl (constant.get_mappings ().get_hirid (),
51+
const_expr);
52+
}
4953

5054
reference = const_expr;
5155
}

gcc/rust/backend/rust-compile-item.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ CompileItem::visit (HIR::ConstantItem &constant)
129129
const_value_expr.get_locus ());
130130
ctx->pop_const_context ();
131131

132-
ctx->push_const (const_expr);
133-
ctx->insert_const_decl (mappings.get_hirid (), const_expr);
132+
if (const_expr != error_mark_node)
133+
{
134+
ctx->push_const (const_expr);
135+
ctx->insert_const_decl (mappings.get_hirid (), const_expr);
136+
}
134137
reference = const_expr;
135138
}
136139

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// { dg-options "-frust-incomplete-and-experimental-compiler-do-not-use" }
2+
#![feature(no_core)]
3+
#![no_core]
4+
5+
struct B<const M: u32> {}
6+
7+
impl<const M: u32> B<M> {
8+
const M: u32 = M;
9+
}
10+
11+
struct C;
12+
13+
impl<const M: u32> C { // { dg-error "unconstrained type parameter" }
14+
const USE_M: u32 = M;
15+
}

0 commit comments

Comments
 (0)