Skip to content

Commit f1e56c4

Browse files
Pasta-coderP-E-P
authored andcommitted
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 4b53420 commit f1e56c4

3 files changed

Lines changed: 25 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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(no_core)]
2+
#![no_core]
3+
4+
struct B<const M: u32> {}
5+
6+
impl<const M: u32> B<M> {
7+
const M: u32 = M;
8+
}
9+
10+
struct C;
11+
12+
impl<const M: u32> C { // { dg-error "unconstrained type parameter" }
13+
const USE_M: u32 = M;
14+
}

0 commit comments

Comments
 (0)