27
27
28
28
namespace Rust {
29
29
namespace AST {
30
- DerivePartialEq::DerivePartialEq (location_t loc)
31
- : DeriveVisitor (loc), expanded (nullptr )
32
- {}
30
+ DerivePartialEq::DerivePartialEq (location_t loc) : DeriveVisitor (loc) {}
33
31
34
- std::unique_ptr<AST::Item>
32
+ std::vector<std:: unique_ptr<AST::Item> >
35
33
DerivePartialEq::go (Item &item)
36
34
{
37
35
item.accept_vis (*this );
38
36
39
- rust_assert (expanded);
40
-
41
37
return std::move (expanded);
42
38
}
43
39
44
- std::unique_ptr<Item>
45
- DerivePartialEq::partial_eq_impl (
40
+ std::vector<std:: unique_ptr<Item> >
41
+ DerivePartialEq::partialeq_impls (
46
42
std::unique_ptr<AssociatedItem> &&eq_fn, std::string name,
47
43
const std::vector<std::unique_ptr<GenericParam>> &type_generics)
48
44
{
49
45
auto eq = builder.type_path (LangItem::Kind::EQ);
46
+ auto speq = builder.type_path (LangItem::Kind::STRUCTURAL_PEQ);
50
47
51
48
auto trait_items = vec (std::move (eq_fn));
52
49
53
- auto generics
50
+ // no extra bound on StructuralPeq
51
+ auto peq_generics
54
52
= setup_impl_generics (name, type_generics, builder.trait_bound (eq));
53
+ auto speq_generics = setup_impl_generics (name, type_generics);
54
+
55
+ auto peq = builder.trait_impl (eq, std::move (peq_generics.self_type ),
56
+ std::move (trait_items),
57
+ std::move (peq_generics.impl ));
58
+
59
+ auto structural_peq
60
+ = builder.trait_impl (speq, std::move (speq_generics.self_type ), {},
61
+ std::move (speq_generics.impl ));
55
62
56
- return builder.trait_impl (eq, std::move (generics.self_type ),
57
- std::move (trait_items),
58
- std::move (generics.impl ));
63
+ return vec (std::move (peq), std::move (structural_peq));
59
64
}
60
65
61
66
std::unique_ptr<AssociatedItem>
@@ -137,7 +142,7 @@ DerivePartialEq::visit_tuple (TupleStruct &item)
137
142
auto fn = eq_fn (build_eq_expression (std::move (fields)), type_name);
138
143
139
144
expanded
140
- = partial_eq_impl (std::move (fn), type_name, item.get_generic_params ());
145
+ = partialeq_impls (std::move (fn), type_name, item.get_generic_params ());
141
146
}
142
147
143
148
void
@@ -153,7 +158,7 @@ DerivePartialEq::visit_struct (StructStruct &item)
153
158
auto fn = eq_fn (build_eq_expression (std::move (fields)), type_name);
154
159
155
160
expanded
156
- = partial_eq_impl (std::move (fn), type_name, item.get_generic_params ());
161
+ = partialeq_impls (std::move (fn), type_name, item.get_generic_params ());
157
162
}
158
163
159
164
MatchCase
@@ -250,11 +255,12 @@ void
250
255
DerivePartialEq::visit_enum (Enum &item)
251
256
{
252
257
auto cases = std::vector<MatchCase> ();
258
+ auto type_name = item.get_identifier ().as_string ();
253
259
254
260
for (auto &variant : item.get_variants ())
255
261
{
256
262
auto variant_path
257
- = builder.variant_path (item. get_identifier (). as_string () ,
263
+ = builder.variant_path (type_name ,
258
264
variant->get_identifier ().as_string ());
259
265
260
266
switch (variant->get_enum_item_kind ())
@@ -290,11 +296,10 @@ DerivePartialEq::visit_enum (Enum &item)
290
296
builder.identifier (" other" ))),
291
297
std::move (cases));
292
298
293
- auto fn = eq_fn (std::move (match), item. get_identifier (). as_string () );
299
+ auto fn = eq_fn (std::move (match), type_name );
294
300
295
301
expanded
296
- = partial_eq_impl (std::move (fn), item.get_identifier ().as_string (),
297
- item.get_generic_params ());
302
+ = partialeq_impls (std::move (fn), type_name, item.get_generic_params ());
298
303
}
299
304
300
305
void
0 commit comments