Skip to content

Commit 816cbd4

Browse files
committed
gccrs: Fix ICE with invalid init expression in TuplePattern LetStmt
The compiler was throwing an ICE when a Type Alias was used as a value in a LetStmt (e.g., `let () = ::X = ();`). This occurred because the backend pattern compiler received an `error_mark_node` for the initialization expression and failed to handle it. This patch adds a check in `CompileStmt` to detect if the initialization expression is an `error_mark_node`. To prevent regression failures in other tests (excess errors), this check is restricted specifically to `TuplePattern`, which was the source of the crash. If detected, we now emit a proper error message and exit early. gcc/rust/ChangeLog: * backend/rust-compile-stmt.cc (CompileStmt::visit): Check for error_mark_node in init expression for TuplePatterns and exit early if found. gcc/testsuite/ChangeLog: * rust/compile/issue-4161.rs: New test. Signed-off-by: Harishankar P P <harishankarpp7@gmail.com>
1 parent 341fc10 commit 816cbd4

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ CompileStmt::visit (HIR::LetStmt &stmt)
7474
tree init = CompileExpr::Compile (stmt.get_init_expr (), ctx);
7575
// FIXME use error_mark_node, check that CompileExpr returns error_mark_node
7676
// on failure and make this an assertion
77+
if (init == error_mark_node)
78+
{
79+
if (stmt.get_pattern ().get_pattern_type ()
80+
== HIR::Pattern::PatternType::TUPLE)
81+
{
82+
if (!seen_error ())
83+
rust_error_at (stmt.get_init_expr ().get_locus (),
84+
"expected value, found invalid expression");
85+
return;
86+
}
87+
}
7788
if (init == nullptr)
7889
return;
7990

gcc/rust/checks/lints/rust-lint-marklive.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,6 @@ MarkLive::visit (HIR::TypeAlias &alias)
268268

269269
if (auto hid = mappings.lookup_node_to_hir (ast_node_id))
270270
mark_hir_id (*hid);
271-
else
272-
rust_unreachable ();
273271
}
274272

275273
void
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
type X = ();
3+
4+
fn main() {
5+
let () = ::X = (); // { dg-error "expected value, found invalid expression" }
6+
}

0 commit comments

Comments
 (0)