From: Jayant Chauhan <[email protected]>

This patch introduces a local helper  in DeriveEq.
This removes the duplication of the hardcoded path {core, cmp, Eq}
used in both  and .

gcc/rust/ChangeLog:

        * expand/rust-derive-eq.cc (get_eq_trait_path): New helper.
        (DeriveEq::assert_param_is_eq): Use helper.
        (DeriveEq::eq_impls): Use helper.

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/d2f8f6493738e752660b3deeb34529613f4adf1b

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

 gcc/rust/expand/rust-derive-eq.cc | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/expand/rust-derive-eq.cc 
b/gcc/rust/expand/rust-derive-eq.cc
index 459ec0e09..c0358593b 100644
--- a/gcc/rust/expand/rust-derive-eq.cc
+++ b/gcc/rust/expand/rust-derive-eq.cc
@@ -27,6 +27,12 @@
 namespace Rust {
 namespace AST {
 
+static TypePath
+get_eq_trait_path (Builder &builder)
+{
+  return builder.type_path ({"core", "cmp", "Eq"}, true);
+}
+
 DeriveEq::DeriveEq (location_t loc) : DeriveVisitor (loc) {}
 
 std::vector<std::unique_ptr<AST::Item>>
@@ -61,7 +67,7 @@ std::unique_ptr<Stmt>
 DeriveEq::assert_param_is_eq ()
 {
   auto eq_bound = std::unique_ptr<TypeParamBound> (
-    new TraitBound (builder.type_path ({"core", "cmp", "Eq"}, true), loc));
+    new TraitBound (get_eq_trait_path (builder), loc));
 
   auto sized_bound = std::unique_ptr<TypeParamBound> (
     new TraitBound (builder.type_path (LangItem::Kind::SIZED), loc, false,
@@ -113,9 +119,8 @@ DeriveEq::eq_impls (
   const std::vector<std::unique_ptr<GenericParam>> &type_generics)
 {
   // We create two copies of the type-path to avoid duplicate NodeIds
-  auto eq = builder.type_path ({"core", "cmp", "Eq"}, true);
-  auto eq_bound
-    = builder.trait_bound (builder.type_path ({"core", "cmp", "Eq"}, true));
+  auto eq = get_eq_trait_path (builder);
+  auto eq_bound = builder.trait_bound (get_eq_trait_path (builder));
 
   auto steq = builder.type_path (LangItem::Kind::STRUCTURAL_TEQ);
 

base-commit: 6f7b08727da5854d3d9d2977ee8dbbc4790332f7
-- 
2.52.0

Reply via email to