]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add captures for ClosureExprInnerTyped with nr2
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Fri, 24 Jan 2025 15:02:10 +0000 (16:02 +0100)
committerP-E-P <32375388+P-E-P@users.noreply.github.com>
Fri, 24 Jan 2025 16:31:36 +0000 (16:31 +0000)
Captures were only processed for regular ClosureExprInner.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add
ClosureExprInnerTyped visit implementation.
(add_captures): Add a function to avoid code duplication.
* resolve/rust-late-name-resolver-2.0.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/resolve/rust-late-name-resolver-2.0.cc
gcc/rust/resolve/rust-late-name-resolver-2.0.h

index 1e7f9f1546cf9990233be6f0773909201ab2c75a..b0364d10725c31cb146312b821decce9ba861f8b 100644 (file)
@@ -390,8 +390,9 @@ Late::visit (AST::GenericArg &arg)
   DefaultResolver::visit (arg);
 }
 
-void
-Late::visit (AST::ClosureExprInner &closure)
+template <class Closure>
+static void
+add_captures (Closure &closure, NameResolutionContext &ctx)
 {
   auto vals = ctx.values.peek ().get_values ();
   for (auto &val : vals)
@@ -399,7 +400,19 @@ Late::visit (AST::ClosureExprInner &closure)
       ctx.mappings.add_capture (closure.get_node_id (),
                                val.second.get_node_id ());
     }
+}
 
+void
+Late::visit (AST::ClosureExprInner &closure)
+{
+  add_captures (closure, ctx);
+  DefaultResolver::visit (closure);
+}
+
+void
+Late::visit (AST::ClosureExprInnerTyped &closure)
+{
+  add_captures (closure, ctx);
   DefaultResolver::visit (closure);
 }
 
index 3030261f10bf0e01169df28e575e78c6243e61d0..c7799359624320a14fc778b4ac8af10642e7db6b 100644 (file)
@@ -57,6 +57,7 @@ public:
   void visit (AST::GenericArgs &) override;
   void visit (AST::GenericArg &);
   void visit (AST::ClosureExprInner &) override;
+  void visit (AST::ClosureExprInnerTyped &) override;
 
 private:
   /* Setup Rust's builtin types (u8, i32, !...) in the resolver */