Skip to content

Commit d2f8f64

Browse files
Pasta-coderCohenArthur
authored andcommitted
derive: Factor out Eq trait path generation
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]>
1 parent 6f7b087 commit d2f8f64

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
namespace Rust {
2828
namespace AST {
2929

30+
static TypePath
31+
get_eq_trait_path (Builder &builder)
32+
{
33+
return builder.type_path ({"core", "cmp", "Eq"}, true);
34+
}
35+
3036
DeriveEq::DeriveEq (location_t loc) : DeriveVisitor (loc) {}
3137

3238
std::vector<std::unique_ptr<AST::Item>>
@@ -61,7 +67,7 @@ std::unique_ptr<Stmt>
6167
DeriveEq::assert_param_is_eq ()
6268
{
6369
auto eq_bound = std::unique_ptr<TypeParamBound> (
64-
new TraitBound (builder.type_path ({"core", "cmp", "Eq"}, true), loc));
70+
new TraitBound (get_eq_trait_path (builder), loc));
6571

6672
auto sized_bound = std::unique_ptr<TypeParamBound> (
6773
new TraitBound (builder.type_path (LangItem::Kind::SIZED), loc, false,
@@ -113,9 +119,8 @@ DeriveEq::eq_impls (
113119
const std::vector<std::unique_ptr<GenericParam>> &type_generics)
114120
{
115121
// We create two copies of the type-path to avoid duplicate NodeIds
116-
auto eq = builder.type_path ({"core", "cmp", "Eq"}, true);
117-
auto eq_bound
118-
= builder.trait_bound (builder.type_path ({"core", "cmp", "Eq"}, true));
122+
auto eq = get_eq_trait_path (builder);
123+
auto eq_bound = builder.trait_bound (get_eq_trait_path (builder));
119124

120125
auto steq = builder.type_path (LangItem::Kind::STRUCTURAL_TEQ);
121126

0 commit comments

Comments
 (0)