Skip to content

Commit

Permalink
Add captures for ClosureExprInnerTyped with nr2
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
P-E-P committed Jan 24, 2025
1 parent 2b47316 commit 98d89d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions gcc/rust/resolve/rust-late-name-resolver-2.0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,29 @@ 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)
{
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);
}

Expand Down
1 change: 1 addition & 0 deletions gcc/rust/resolve/rust-late-name-resolver-2.0.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Late : public DefaultResolver
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 */
Expand Down

0 comments on commit 98d89d5

Please sign in to comment.