From: Jayant Chauhan <[email protected]>

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 Rust-GCC#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 <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/4c81795f42a0bcad435f832474badbfc8f8efd43

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4394

 gcc/rust/ast/rust-ast-builder.cc     | 10 ++++++++++
 gcc/rust/ast/rust-ast-builder.h      |  4 ++++
 gcc/rust/expand/rust-derive-clone.cc |  7 +------
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index cb62f76f0..46a7883b5 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -737,5 +737,15 @@ Builder::new_generic_args (GenericArgs &args)
                      std::move (binding_args), locus);
 }
 
+std::unique_ptr<Expr>
+Builder::qualified_call (std::vector<std::string> &&segments,
+                        std::vector<std::unique_ptr<Expr>> &&args) const
+{
+  auto path = std::unique_ptr<Expr> (
+    new PathInExpression (path_in_expression (std::move (segments))));
+
+  return call (std::move (path), std::move (args));
+}
+
 } // namespace AST
 } // namespace Rust
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index 37d22e738..1b642e4af 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -169,6 +169,10 @@ public:
                                std::vector<PathExprSegment> &&segments
                                = {}) const;
 
+  std::unique_ptr<Expr>
+  qualified_call (std::vector<std::string> &&segments,
+                 std::vector<std::unique_ptr<Expr>> &&args) const;
+
   /* Self parameter for a function definition (`&self`) */
   std::unique_ptr<Param> self_ref_param (bool mutability = false) const;
   /* A regular named function parameter for a definition (`a: type`) */
diff --git a/gcc/rust/expand/rust-derive-clone.cc 
b/gcc/rust/expand/rust-derive-clone.cc
index fa0c7ab02..d83743786 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -42,13 +42,10 @@ DeriveClone::clone_call (std::unique_ptr<Expr> &&to_clone)
 
   // Not sure how to call it properly in the meantime...
 
-  auto path = std::unique_ptr<Expr> (
-    new PathInExpression (builder.path_in_expression ({"Clone", "clone"})));
-
   auto args = std::vector<std::unique_ptr<Expr>> ();
   args.emplace_back (std::move (to_clone));
 
-  return builder.call (std::move (path), std::move (args));
+  return builder.qualified_call ({"Clone", "clone"}, std::move (args));
 }
 
 /**
@@ -104,8 +101,6 @@ DeriveClone::clone_impl (
                             std::move (generics.impl));
 }
 
-// TODO: Create new `make_qualified_call` helper function
-
 DeriveClone::DeriveClone (location_t loc)
   : DeriveVisitor (loc), expanded (nullptr)
 {}

base-commit: cb12ae0400cf3b4419c9b9fe145e82440355e1d3
-- 
2.52.0

Reply via email to