From: Arthur Cohen Date: Mon, 19 May 2025 10:27:17 +0000 (+0200) Subject: gccrs: ast: Check before visiting a while-let's label X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=4e06ba151c4131bde8ce88996a980e56349acc8d;p=thirdparty%2Fgcc.git 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 --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc index fd45fb1060d..ca7b3e495d0 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 00000000000..e04e4b59d1d --- /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 {} +}