]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: ast: Check before visiting a while-let's label
authorArthur Cohen <arthur.cohen@embecosm.com>
Mon, 19 May 2025 10:27:17 +0000 (12:27 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:54 +0000 (16:36 +0200)
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.

gcc/rust/ast/rust-ast-visitor.cc
gcc/testsuite/rust/compile/while_let_without_label.rs [new file with mode: 0644]

index fd45fb1060d3d82231afffaad6060cd12c6d98dc..ca7b3e495d0ffcb6e01fd2f546f2d34a6143b9c6 100644 (file)
@@ -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 (file)
index 0000000..e04e4b5
--- /dev/null
@@ -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 {}
+}