Skip to content

Commit 515b5a8

Browse files
committed
ast: Add qualified_call helper to Builder
This patch implements the `qualified_call` helper method in the `Builder` class. This logic was previously intended to be a local helper in `DeriveClone`, but moving it to the `Builder` allows it to be reused across the compiler for constructing qualified function calls. It updates `DeriveClone::clone_call` to use this new `Builder` method, simplifying the code and resolving the TODO. Fixes #4393 gcc/rust/ChangeLog: * ast/rust-ast-builder.h (Builder::qualified_call): New method declaration. * ast/rust-ast-builder.cc (Builder::qualified_call): Implement new method. * expand/rust-derive-clone.cc (DeriveClone::clone_call): Use builder.qualified_call. Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
1 parent 23de527 commit 515b5a8

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

gcc/rust/ast/rust-ast-builder.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,5 +737,15 @@ Builder::new_generic_args (GenericArgs &args)
737737
std::move (binding_args), locus);
738738
}
739739

740+
std::unique_ptr<Expr>
741+
Builder::qualified_call (std::vector<std::string> &&segments,
742+
std::vector<std::unique_ptr<Expr>> &&args) const
743+
{
744+
auto path = std::unique_ptr<Expr> (
745+
new PathInExpression (path_in_expression (std::move (segments))));
746+
747+
return call (std::move (path), std::move (args));
748+
}
749+
740750
} // namespace AST
741751
} // namespace Rust

gcc/rust/ast/rust-ast-builder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ class Builder
169169
std::vector<PathExprSegment> &&segments
170170
= {}) const;
171171

172+
std::unique_ptr<Expr>
173+
qualified_call (std::vector<std::string> &&segments,
174+
std::vector<std::unique_ptr<Expr>> &&args) const;
175+
172176
/* Self parameter for a function definition (`&self`) */
173177
std::unique_ptr<Param> self_ref_param (bool mutability = false) const;
174178
/* A regular named function parameter for a definition (`a: type`) */

gcc/rust/expand/rust-derive-clone.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@ DeriveClone::clone_call (std::unique_ptr<Expr> &&to_clone)
4141
// able to directly call `::core::clone::Clone::clone()`
4242

4343
// Not sure how to call it properly in the meantime...
44-
4544
auto path = std::unique_ptr<Expr> (
4645
new PathInExpression (builder.path_in_expression ({"Clone", "clone"})));
4746

4847
auto args = std::vector<std::unique_ptr<Expr>> ();
4948
args.emplace_back (std::move (to_clone));
5049

51-
return builder.call (std::move (path), std::move (args));
50+
return builder.qualified_call ({"Clone", "clone"}, std::move (args));
5251
}
5352

5453
/**
@@ -104,8 +103,6 @@ DeriveClone::clone_impl (
104103
std::move (generics.impl));
105104
}
106105

107-
// TODO: Create new `make_qualified_call` helper function
108-
109106
DeriveClone::DeriveClone (location_t loc)
110107
: DeriveVisitor (loc), expanded (nullptr)
111108
{}

0 commit comments

Comments
 (0)