@@ -110,8 +110,8 @@ impl Traits {
110
110
let pattern = quote ! { Self } ;
111
111
112
112
match & data. fields {
113
- Fields :: Named ( fields) => self . build_struct ( debug_name, & pattern, None , fields) ,
114
- Fields :: Unnamed ( fields) => self . generate_tuple ( debug_name, & pattern, None , fields) ,
113
+ Fields :: Named ( fields) => self . build_for_struct ( debug_name, & pattern, None , fields) ,
114
+ Fields :: Unnamed ( fields) => self . build_for_tuple ( debug_name, & pattern, None , fields) ,
115
115
fields @ Fields :: Unit => return Err ( Error :: new (
116
116
fields. span ( ) ,
117
117
"Using `derive_where` on unit struct is not supported as unit structs don't support generics." ) ) ,
@@ -129,20 +129,20 @@ impl Traits {
129
129
let pattern = quote ! { Self :: #debug_name } ;
130
130
131
131
match & variant. fields {
132
- Fields :: Named ( fields) => self . build_struct (
132
+ Fields :: Named ( fields) => self . build_for_struct (
133
133
debug_name,
134
134
& pattern,
135
135
Some ( ( index, & variants) ) ,
136
136
fields,
137
137
) ,
138
- Fields :: Unnamed ( fields) => self . generate_tuple (
138
+ Fields :: Unnamed ( fields) => self . build_for_tuple (
139
139
debug_name,
140
140
& pattern,
141
141
Some ( ( index, & variants) ) ,
142
142
fields,
143
143
) ,
144
144
Fields :: Unit => {
145
- self . generate_unit ( debug_name, & pattern, Some ( ( index, & variants) ) )
145
+ self . build_for_unit ( debug_name, & pattern, Some ( ( index, & variants) ) )
146
146
}
147
147
}
148
148
} )
@@ -288,8 +288,10 @@ impl Traits {
288
288
}
289
289
}
290
290
291
- /// Build method body if type is a structure.
292
- fn build_struct (
291
+ /// Build method body if type is a structure. `pattern` is used to
292
+ /// generalize over matching against a `struct` or an `enum`: `Self` for
293
+ /// `struct`s and `Self::Variant` for `enum`s.
294
+ fn build_for_struct (
293
295
self ,
294
296
debug_name : & Ident ,
295
297
pattern : & TokenStream ,
@@ -371,8 +373,9 @@ impl Traits {
371
373
}
372
374
}
373
375
374
- /// Build method body if type is a tuple.
375
- fn generate_tuple (
376
+ /// Build method body if type is a tuple. See description for `pattern` in
377
+ /// [`Self::build_for_struct`].
378
+ fn build_for_tuple (
376
379
self ,
377
380
debug_name : & Ident ,
378
381
pattern : & TokenStream ,
@@ -447,8 +450,9 @@ impl Traits {
447
450
}
448
451
}
449
452
450
- /// Build method body if type is a unit.
451
- fn generate_unit (
453
+ /// Build method body if type is a unit. See description for `pattern` in
454
+ /// [`Self::build_for_struct`].
455
+ fn build_for_unit (
452
456
self ,
453
457
debug_name : & Ident ,
454
458
pattern : & TokenStream ,
0 commit comments