]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: nr2.0: Add proper handling for WhileLet loops.
authorArthur Cohen <arthur.cohen@embecosm.com>
Fri, 4 Jul 2025 13:40:02 +0000 (15:40 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:54 +0000 (16:36 +0200)
gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): New visitor.
* resolve/rust-late-name-resolver-2.0.h: Declare it.
* resolve/rust-name-resolution-context.h (enum class): New binding context.

gcc/rust/resolve/rust-late-name-resolver-2.0.cc
gcc/rust/resolve/rust-late-name-resolver-2.0.h
gcc/rust/resolve/rust-name-resolution-context.h

index 3f6e432b851216e1c39802a520d28e89536a22b6..76fd2bd17aa8c79deafc06182ad6411f805c35d3 100644 (file)
@@ -19,6 +19,7 @@
 #include "optional.h"
 #include "rust-ast-full.h"
 #include "rust-diagnostics.h"
+#include "rust-expr.h"
 #include "rust-hir-map.h"
 #include "rust-late-name-resolver-2.0.h"
 #include "rust-default-resolver.h"
@@ -208,6 +209,28 @@ Late::visit (AST::LetStmt &let)
   //      let.get_node_id (), [] () {});
 }
 
+void
+Late::visit (AST::WhileLetLoopExpr &while_let)
+{
+  DefaultASTVisitor::visit_outer_attrs (while_let);
+
+  if (while_let.has_loop_label ())
+    visit (while_let.get_loop_label ());
+
+  // visit expression before pattern
+  // this makes variable shadowing work properly
+  visit (while_let.get_scrutinee_expr ());
+
+  ctx.bindings.enter (BindingSource::WhileLet);
+
+  for (auto &pattern : while_let.get_patterns ())
+    visit (pattern);
+
+  ctx.bindings.exit ();
+
+  visit (while_let.get_loop_block ());
+}
+
 static void
 visit_identifier_as_pattern (NameResolutionContext &ctx,
                             const Identifier &ident, location_t locus,
index 65af6139e80a6fd262f7980fa32e5322213c4499..95540e34005329ff002fd57a3a5a4e631bec0da4 100644 (file)
@@ -42,6 +42,7 @@ public:
 
   // some more label declarations
   void visit (AST::LetStmt &) override;
+  void visit (AST::WhileLetLoopExpr &) override;
   // TODO: Do we need this?
   // void visit (AST::Method &) override;
   void visit (AST::IdentifierPattern &) override;
index 0180919db7e72f8592be8ccc8cc46263ed1c2b97..558b3cab664740fc97ce91dc1243b97d57456a2e 100644 (file)
@@ -198,6 +198,7 @@ enum class BindingSource
   Match,
   Let,
   IfLet,
+  WhileLet,
   For,
   /* Closure param or function param */
   Param