@@ -10,15 +10,15 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
10
10
let ident = & cx. ast . ident ;
11
11
let lt = cx. lt ;
12
12
13
- let clone = & cx. toks . clone ;
14
- let copy = & cx. toks . copy ;
15
- let default = & cx. toks . default ;
16
- let eq = & cx. toks . eq ;
17
- let key_trait = & cx. toks . key_trait ;
18
- let mem = & cx. toks . mem ;
19
- let option = & cx. toks . option ;
20
- let partial_eq = & cx. toks . partial_eq ;
21
- let storage_trait = & cx. toks . storage_trait ;
13
+ let clone_t = cx. toks . clone_t ( ) ;
14
+ let copy_t = cx. toks . copy_t ( ) ;
15
+ let default_t = cx. toks . default_t ( ) ;
16
+ let eq_t = cx. toks . eq_t ( ) ;
17
+ let key_t = cx. toks . key_t ( ) ;
18
+ let mem = cx. toks . mem ( ) ;
19
+ let option = cx. toks . option ( ) ;
20
+ let partial_eq_t = cx. toks . partial_eq_t ( ) ;
21
+ let storage_t = cx. toks . storage_t ( ) ;
22
22
23
23
let const_wrapper = Ident :: new (
24
24
& format ! ( "__IMPL_KEY_FOR_{}" , cx. ast. ident) ,
@@ -32,6 +32,7 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
32
32
let mut field_inits = Vec :: new ( ) ;
33
33
let mut field_clones = Vec :: new ( ) ;
34
34
let mut field_partial_eqs = Vec :: new ( ) ;
35
+ let mut field_partial_not_eqs = Vec :: new ( ) ;
35
36
let mut contains_key = Vec :: new ( ) ;
36
37
let mut get = Vec :: new ( ) ;
37
38
let mut get_mut = Vec :: new ( ) ;
@@ -46,14 +47,21 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
46
47
let var = & variant. ident ;
47
48
let name = Ident :: new ( & format ! ( "f{}" , index) , Span :: call_site ( ) ) ;
48
49
49
- field_inits. push ( quote ! ( #name: #default :: default ( ) ) ) ;
50
- field_clones. push ( quote ! ( #name: #clone:: clone( & self . #name) ) ) ;
50
+ field_inits. push ( quote ! ( #name: #default_t:: default ( ) ) ) ;
51
+ field_clones. push ( quote ! ( #name: #clone_t:: clone( & self . #name) ) ) ;
52
+
51
53
field_partial_eqs. push ( quote ! {
52
- if self . #name != other. #name {
54
+ if #partial_eq_t :: ne ( & self . #name, & other. #name) {
53
55
return false ;
54
56
}
55
57
} ) ;
56
58
59
+ field_partial_not_eqs. push ( quote ! {
60
+ if #partial_eq_t:: ne( & self . #name, & other. #name) {
61
+ return true ;
62
+ }
63
+ } ) ;
64
+
57
65
let kind = match & variant. fields {
58
66
Fields :: Unit => {
59
67
len. push ( quote ! ( usize :: from( #option:: is_some( & self . #name) ) ) ) ;
@@ -67,7 +75,7 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
67
75
insert. push ( quote ! ( #mem:: replace( & mut self . #name, #option:: Some ( value) ) ) ) ;
68
76
remove. push ( quote ! ( #mem:: replace( & mut self . #name, #option:: None ) ) ) ;
69
77
retain. push ( quote ! {
70
- if let Some ( val) = #option:: as_mut( & mut self . #name) {
78
+ if let #option :: Some ( val) = #option:: as_mut( & mut self . #name) {
71
79
if !func( #ident:: #var, val) {
72
80
self . #name = None ;
73
81
}
@@ -86,8 +94,8 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
86
94
}
87
95
88
96
let element = unnamed. unnamed . first ( ) . expect ( "Expected one element" ) ;
89
- let storage = quote ! ( <#element as #key_trait >:: Storage :: <V >) ;
90
- let as_storage = quote ! ( <#storage as #storage_trait <#element, V >>) ;
97
+ let storage = quote ! ( <#element as #key_t >:: Storage :: <V >) ;
98
+ let as_storage = quote ! ( <#storage as #storage_t <#element, V >>) ;
91
99
92
100
len. push ( quote ! ( #as_storage:: len( & self . #name) ) ) ;
93
101
is_empty. push ( quote ! ( #as_storage:: is_empty( & self . #name) ) ) ;
@@ -105,7 +113,7 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
105
113
#as_storage:: retain( & mut self . #name, |k, v| func( #ident:: #var( k) , v) ) ;
106
114
} ) ;
107
115
108
- copy_bounds. push ( quote ! ( #storage: #copy ) ) ;
116
+ copy_bounds. push ( quote ! ( #storage: #copy_t ) ) ;
109
117
110
118
FieldKind :: Complex {
111
119
element : quote ! ( #element) ,
@@ -131,7 +139,7 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
131
139
let mut iter_clone = Vec :: new ( ) ;
132
140
133
141
for FieldSpec { name, .. } in & field_specs {
134
- iter_clone. push ( quote ! ( #name: #clone :: clone( & self . #name) ) ) ;
142
+ iter_clone. push ( quote ! ( #name: #clone_t :: clone( & self . #name) ) ) ;
135
143
}
136
144
137
145
let pattern = & pattern;
@@ -157,7 +165,7 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
157
165
}
158
166
159
167
#[ automatically_derived]
160
- impl <V > #clone for Storage <V > where V : #clone {
168
+ impl <V > #clone_t for Storage <V > where V : #clone_t {
161
169
#[ inline]
162
170
fn clone( & self ) -> Storage <V > {
163
171
Storage {
@@ -167,22 +175,28 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
167
175
}
168
176
169
177
#[ automatically_derived]
170
- impl <V > #copy for Storage <V > where V : #copy , #( #copy_bounds, ) * { }
178
+ impl <V > #copy_t for Storage <V > where V : #copy_t , #( #copy_bounds, ) * { }
171
179
172
180
#[ automatically_derived]
173
- impl <V > #partial_eq for Storage <V > where V : #partial_eq {
181
+ impl <V > #partial_eq_t for Storage <V > where V : #partial_eq_t {
174
182
#[ inline]
175
183
fn eq( & self , other: & Storage <V >) -> bool {
176
184
#( #field_partial_eqs; ) *
177
185
true
178
186
}
187
+
188
+ #[ inline]
189
+ fn ne( & self , other: & Storage <V >) -> bool {
190
+ #( #field_partial_not_eqs; ) *
191
+ false
192
+ }
179
193
}
180
194
181
195
#[ automatically_derived]
182
- impl <V > #eq for Storage <V > where V : #eq { }
196
+ impl <V > #eq_t for Storage <V > where V : #eq_t { }
183
197
184
198
#[ automatically_derived]
185
- impl <V > #default for Storage <V > {
199
+ impl <V > #default_t for Storage <V > {
186
200
#[ inline]
187
201
fn default ( ) -> Self {
188
202
Self {
@@ -192,7 +206,7 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
192
206
}
193
207
194
208
#[ automatically_derived]
195
- impl <V > #storage_trait <#ident, V > for Storage <V > {
209
+ impl <V > #storage_t <#ident, V > for Storage <V > {
196
210
type Iter <#lt> = Iter <#lt, V > where V : #lt;
197
211
type Keys <#lt> = Keys <#lt, V > where V : #lt;
198
212
type Values <#lt> = Values <#lt, V > where V : #lt;
@@ -314,7 +328,7 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
314
328
}
315
329
316
330
#[ automatically_derived]
317
- impl #key_trait for #ident {
331
+ impl #key_t for #ident {
318
332
type Storage <V > = Storage <V >;
319
333
}
320
334
@@ -339,9 +353,9 @@ fn build_iter_next(
339
353
assoc_type : & Ident ,
340
354
lt : Option < & syn:: Lifetime > ,
341
355
) -> Result < ( ) , ( ) > {
342
- let option = & cx. toks . option ;
343
- let iterator_t = & cx. toks . iterator_t ;
344
- let double_ended_iterator_t = & cx. toks . double_ended_iterator_t ;
356
+ let option = cx. toks . option ( ) ;
357
+ let iterator_t = cx. toks . iterator_t ( ) ;
358
+ let double_ended_iterator_t = cx. toks . double_ended_iterator_t ( ) ;
345
359
let ident = & cx. ast . ident ;
346
360
347
361
for FieldSpec {
@@ -417,13 +431,14 @@ fn build_iter_impl(
417
431
let type_name = syn:: Ident :: new ( id, Span :: call_site ( ) ) ;
418
432
419
433
let lt = cx. lt ;
420
- let option = & cx. toks . option ;
421
- let iterator_t = & cx. toks . iterator_t ;
422
- let double_ended_iterator_t = & cx. toks . double_ended_iterator_t ;
423
- let clone = & cx. toks . clone ;
424
434
let ident = & cx. ast . ident ;
425
435
let vis = & cx. ast . vis ;
426
436
437
+ let option = cx. toks . option ( ) ;
438
+ let iterator_t = cx. toks . iterator_t ( ) ;
439
+ let double_ended_iterator_t = cx. toks . double_ended_iterator_t ( ) ;
440
+ let clone_t = cx. toks . clone_t ( ) ;
441
+
427
442
let mut step_forward = IteratorNext :: default ( ) ;
428
443
let mut step_backward = IteratorNextBack :: default ( ) ;
429
444
@@ -441,7 +456,7 @@ fn build_iter_impl(
441
456
) ?;
442
457
443
458
for FieldSpec { name, kind, .. } in field_specs {
444
- iter_clone. push ( quote ! ( #name: #clone :: clone( & self . #name) ) ) ;
459
+ iter_clone. push ( quote ! ( #name: #clone_t :: clone( & self . #name) ) ) ;
445
460
446
461
match kind {
447
462
FieldKind :: Simple => {
@@ -470,7 +485,7 @@ fn build_iter_impl(
470
485
}
471
486
472
487
#[ automatically_derived]
473
- impl <#lt, V > #clone for #type_name<#lt, V > where V : #lt {
488
+ impl <#lt, V > #clone_t for #type_name<#lt, V > where V : #lt {
474
489
#[ inline]
475
490
fn clone( & self ) -> Self {
476
491
Self {
@@ -514,15 +529,16 @@ fn build_keys_impl(
514
529
let type_name = syn:: Ident :: new ( id, Span :: call_site ( ) ) ;
515
530
516
531
let lt = cx. lt ;
517
- let option = & cx. toks . option ;
518
- let iterator_t = & cx. toks . iterator_t ;
519
- let double_ended_iterator_t = & cx. toks . double_ended_iterator_t ;
520
- let clone = & cx. toks . clone ;
521
- let bool_type = & cx. toks . bool_type ;
522
- let mem = & cx. toks . mem ;
523
532
let ident = & cx. ast . ident ;
524
533
let vis = & cx. ast . vis ;
525
534
535
+ let bool_type = cx. toks . bool_type ( ) ;
536
+ let clone_t = cx. toks . clone_t ( ) ;
537
+ let double_ended_iterator_t = cx. toks . double_ended_iterator_t ( ) ;
538
+ let iterator_t = cx. toks . iterator_t ( ) ;
539
+ let mem = cx. toks . mem ( ) ;
540
+ let option = cx. toks . option ( ) ;
541
+
526
542
let mut step_forward = IteratorNext :: default ( ) ;
527
543
let mut step_backward = IteratorNextBack :: default ( ) ;
528
544
@@ -539,7 +555,7 @@ fn build_keys_impl(
539
555
..
540
556
} in field_specs
541
557
{
542
- iter_clone. push ( quote ! ( #name: #clone :: clone( & self . #name) ) ) ;
558
+ iter_clone. push ( quote ! ( #name: #clone_t :: clone( & self . #name) ) ) ;
543
559
544
560
match kind {
545
561
FieldKind :: Simple => {
@@ -608,7 +624,7 @@ fn build_keys_impl(
608
624
}
609
625
610
626
#[ automatically_derived]
611
- impl <#lt, V > #clone for #type_name<#lt, V > where V : #lt {
627
+ impl <#lt, V > #clone_t for #type_name<#lt, V > where V : #lt {
612
628
#[ inline]
613
629
fn clone( & self ) -> Self {
614
630
Self {
@@ -652,12 +668,13 @@ fn build_values_impl(
652
668
let type_name = syn:: Ident :: new ( id, Span :: call_site ( ) ) ;
653
669
654
670
let lt = cx. lt ;
655
- let option = & cx. toks . option ;
656
- let iterator_t = & cx. toks . iterator_t ;
657
- let double_ended_iterator_t = & cx. toks . double_ended_iterator_t ;
658
- let clone = & cx. toks . clone ;
659
671
let vis = & cx. ast . vis ;
660
672
673
+ let clone_t = cx. toks . clone_t ( ) ;
674
+ let double_ended_iterator_t = cx. toks . double_ended_iterator_t ( ) ;
675
+ let iterator_t = cx. toks . iterator_t ( ) ;
676
+ let option = cx. toks . option ( ) ;
677
+
661
678
let mut step_forward = IteratorNext :: default ( ) ;
662
679
let mut step_backward = IteratorNextBack :: default ( ) ;
663
680
@@ -673,7 +690,7 @@ fn build_values_impl(
673
690
..
674
691
} in field_specs
675
692
{
676
- iter_clone. push ( quote ! ( #name: #clone :: clone( & self . #name) ) ) ;
693
+ iter_clone. push ( quote ! ( #name: #clone_t :: clone( & self . #name) ) ) ;
677
694
678
695
match kind {
679
696
FieldKind :: Simple => {
@@ -742,7 +759,7 @@ fn build_values_impl(
742
759
}
743
760
744
761
#[ automatically_derived]
745
- impl <#lt, V > #clone for #type_name<#lt, V > where V : #lt {
762
+ impl <#lt, V > #clone_t for #type_name<#lt, V > where V : #lt {
746
763
#[ inline]
747
764
fn clone( & self ) -> Self {
748
765
Self {
@@ -785,12 +802,13 @@ fn build_iter_mut_impl(
785
802
) -> Result < ( TokenStream , Vec < TokenStream > ) , ( ) > {
786
803
let type_name = syn:: Ident :: new ( id, Span :: call_site ( ) ) ;
787
804
788
- let lt = cx. lt ;
789
805
let ident = & cx. ast . ident ;
806
+ let lt = cx. lt ;
790
807
let vis = & cx. ast . vis ;
791
- let iterator_t = & cx. toks . iterator_t ;
792
- let double_ended_iterator_t = & cx. toks . double_ended_iterator_t ;
793
- let option = & cx. toks . option ;
808
+
809
+ let double_ended_iterator_t = cx. toks . double_ended_iterator_t ( ) ;
810
+ let iterator_t = cx. toks . iterator_t ( ) ;
811
+ let option = cx. toks . option ( ) ;
794
812
795
813
let mut step_forward = IteratorNext :: default ( ) ;
796
814
let mut step_backward = IteratorNextBack :: default ( ) ;
@@ -871,11 +889,12 @@ fn build_values_mut_impl(
871
889
let type_name = syn:: Ident :: new ( id, Span :: call_site ( ) ) ;
872
890
873
891
let lt = cx. lt ;
874
- let option = & cx. toks . option ;
875
- let iterator_t = & cx. toks . iterator_t ;
876
- let clone = & cx. toks . clone ;
877
892
let vis = & cx. ast . vis ;
878
- let double_ended_iterator_t = & cx. toks . double_ended_iterator_t ;
893
+
894
+ let option = cx. toks . option ( ) ;
895
+ let iterator_t = cx. toks . iterator_t ( ) ;
896
+ let clone_t = cx. toks . clone_t ( ) ;
897
+ let double_ended_iterator_t = cx. toks . double_ended_iterator_t ( ) ;
879
898
880
899
let mut step_forward = IteratorNext :: default ( ) ;
881
900
let mut step_backward = IteratorNextBack :: default ( ) ;
@@ -892,7 +911,7 @@ fn build_values_mut_impl(
892
911
..
893
912
} in field_specs
894
913
{
895
- iter_clone. push ( quote ! ( #name: #clone :: clone( & self . #name) ) ) ;
914
+ iter_clone. push ( quote ! ( #name: #clone_t :: clone( & self . #name) ) ) ;
896
915
897
916
match kind {
898
917
FieldKind :: Simple => {
@@ -994,10 +1013,11 @@ fn build_into_iter_impl(
994
1013
995
1014
let ident = & cx. ast . ident ;
996
1015
let vis = & cx. ast . vis ;
997
- let option = & cx. toks . option ;
998
- let clone = & cx. toks . clone ;
999
- let iterator_t = & cx. toks . iterator_t ;
1000
- let double_ended_iterator_t = & cx. toks . double_ended_iterator_t ;
1016
+
1017
+ let option = cx. toks . option ( ) ;
1018
+ let clone_t = cx. toks . clone_t ( ) ;
1019
+ let iterator_t = cx. toks . iterator_t ( ) ;
1020
+ let double_ended_iterator_t = cx. toks . double_ended_iterator_t ( ) ;
1001
1021
1002
1022
let mut step_forward = IteratorNext :: default ( ) ;
1003
1023
let mut step_backward = IteratorNextBack :: default ( ) ;
@@ -1017,7 +1037,7 @@ fn build_into_iter_impl(
1017
1037
) ?;
1018
1038
1019
1039
for FieldSpec { name, kind, .. } in field_specs {
1020
- field_clone. push ( quote ! ( #name: #clone :: clone( & self . #name) ) ) ;
1040
+ field_clone. push ( quote ! ( #name: #clone_t :: clone( & self . #name) ) ) ;
1021
1041
1022
1042
match kind {
1023
1043
FieldKind :: Simple => {
@@ -1031,7 +1051,7 @@ fn build_into_iter_impl(
1031
1051
} => {
1032
1052
field_decls. push ( quote ! ( #name: #as_storage:: IntoIter ) ) ;
1033
1053
init. push ( quote ! ( #name: #storage:: into_iter( self . #name) ) ) ;
1034
- clone_bounds. push ( quote ! ( #as_storage:: IntoIter : #clone ) ) ;
1054
+ clone_bounds. push ( quote ! ( #as_storage:: IntoIter : #clone_t ) ) ;
1035
1055
}
1036
1056
}
1037
1057
}
@@ -1046,7 +1066,7 @@ fn build_into_iter_impl(
1046
1066
}
1047
1067
1048
1068
#[ automatically_derived]
1049
- impl <V > #clone for #type_name<V > where V : Clone , #( #clone_bounds, ) * {
1069
+ impl <V > #clone_t for #type_name<V > where V : Clone , #( #clone_bounds, ) * {
1050
1070
#[ inline]
1051
1071
fn clone( & self ) -> Self {
1052
1072
Self {
@@ -1143,14 +1163,15 @@ fn build_entry_impl(cx: &Ctxt<'_>, field_specs: &[FieldSpec<'_>]) -> Result<Toke
1143
1163
let ident = & cx. ast . ident ;
1144
1164
let vis = & cx. ast . vis ;
1145
1165
let lt = cx. lt ;
1146
- let option = & cx. toks . option ;
1147
- let storage_entry_trait = & cx. toks . storage_entry_trait ;
1148
- let occupied_entry_trait = & cx. toks . occupied_entry_trait ;
1149
- let vacant_entry_trait = & cx. toks . vacant_entry_trait ;
1150
- let entry_enum = & cx. toks . entry_enum ;
1151
- let option_bucket_option = & cx. toks . option_bucket_option ;
1152
- let option_bucket_some = & cx. toks . option_bucket_some ;
1153
- let option_bucket_none = & cx. toks . option_bucket_none ;
1166
+
1167
+ let entry_enum = cx. toks . entry_enum ( ) ;
1168
+ let occupied_entry_trait = cx. toks . occupied_entry_t ( ) ;
1169
+ let option = cx. toks . option ( ) ;
1170
+ let option_bucket_none = cx. toks . option_bucket_none ( ) ;
1171
+ let option_bucket_option = cx. toks . option_bucket_option ( ) ;
1172
+ let option_bucket_some = cx. toks . option_bucket_some ( ) ;
1173
+ let storage_entry_trait = cx. toks . storage_entry_t ( ) ;
1174
+ let vacant_entry_trait = cx. toks . vacant_entry_t ( ) ;
1154
1175
1155
1176
let mut init = Vec :: new ( ) ;
1156
1177
let mut occupied_variant = Vec :: new ( ) ;
0 commit comments