https://gcc.gnu.org/g:4e06ba151c4131bde8ce88996a980e56349acc8d
commit r16-2921-g4e06ba151c4131bde8ce88996a980e56349acc8d Author: Arthur Cohen <arthur.co...@embecosm.com> Date: Mon May 19 12:27:17 2025 +0200 gccrs: ast: Check before visiting a while-let's label gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check that the WhileLet has a label before visiting it. gcc/testsuite/ChangeLog: * rust/compile/while_let_without_label.rs: New test. Diff: --- gcc/rust/ast/rust-ast-visitor.cc | 5 ++++- gcc/testsuite/rust/compile/while_let_without_label.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc index fd45fb1060d3..ca7b3e495d0f 100644 --- a/gcc/rust/ast/rust-ast-visitor.cc +++ b/gcc/rust/ast/rust-ast-visitor.cc @@ -601,7 +601,10 @@ DefaultASTVisitor::visit (AST::WhileLetLoopExpr &expr) visit_outer_attrs (expr); for (auto &pattern : expr.get_patterns ()) visit (pattern); - visit (expr.get_loop_label ()); + + if (expr.has_loop_label ()) + visit (expr.get_loop_label ()); + visit (expr.get_scrutinee_expr ()); visit (expr.get_loop_block ()); } diff --git a/gcc/testsuite/rust/compile/while_let_without_label.rs b/gcc/testsuite/rust/compile/while_let_without_label.rs new file mode 100644 index 000000000000..e04e4b59d1df --- /dev/null +++ b/gcc/testsuite/rust/compile/while_let_without_label.rs @@ -0,0 +1,11 @@ +// { dg-additional-options "-frust-compile-until=lowering" } + +enum Foo { + A(i32), +} + +fn main() { + let b = Foo::A(15); + + while let Foo::A(x) = b {} +}