@@ -194,6 +194,7 @@ struct BasicAdtInfo {
194
194
/// second field is `Some(ty)` if it's a const param of type `ty`, `None` if it's a type param.
195
195
/// third fields is where bounds, if any
196
196
param_types : Vec < ( tt:: Subtree , Option < tt:: Subtree > , Option < tt:: Subtree > ) > ,
197
+ where_clause : Vec < tt:: Subtree > ,
197
198
associated_types : Vec < tt:: Subtree > ,
198
199
}
199
200
@@ -202,10 +203,11 @@ fn parse_adt(
202
203
adt : & ast:: Adt ,
203
204
call_site : Span ,
204
205
) -> Result < BasicAdtInfo , ExpandError > {
205
- let ( name, generic_param_list, shape) = match adt {
206
+ let ( name, generic_param_list, where_clause , shape) = match adt {
206
207
ast:: Adt :: Struct ( it) => (
207
208
it. name ( ) ,
208
209
it. generic_param_list ( ) ,
210
+ it. where_clause ( ) ,
209
211
AdtShape :: Struct ( VariantShape :: from ( tm, it. field_list ( ) ) ?) ,
210
212
) ,
211
213
ast:: Adt :: Enum ( it) => {
@@ -217,6 +219,7 @@ fn parse_adt(
217
219
(
218
220
it. name ( ) ,
219
221
it. generic_param_list ( ) ,
222
+ it. where_clause ( ) ,
220
223
AdtShape :: Enum {
221
224
default_variant,
222
225
variants : it
@@ -233,7 +236,9 @@ fn parse_adt(
233
236
} ,
234
237
)
235
238
}
236
- ast:: Adt :: Union ( it) => ( it. name ( ) , it. generic_param_list ( ) , AdtShape :: Union ) ,
239
+ ast:: Adt :: Union ( it) => {
240
+ ( it. name ( ) , it. generic_param_list ( ) , it. where_clause ( ) , AdtShape :: Union )
241
+ }
237
242
} ;
238
243
239
244
let mut param_type_set: FxHashSet < Name > = FxHashSet :: default ( ) ;
@@ -274,6 +279,14 @@ fn parse_adt(
274
279
} )
275
280
. collect ( ) ;
276
281
282
+ let where_clause = if let Some ( w) = where_clause {
283
+ w. predicates ( )
284
+ . map ( |it| mbe:: syntax_node_to_token_tree ( it. syntax ( ) , tm, call_site) )
285
+ . collect ( )
286
+ } else {
287
+ vec ! [ ]
288
+ } ;
289
+
277
290
// For a generic parameter `T`, when shorthand associated type `T::Assoc` appears in field
278
291
// types (of any variant for enums), we generate trait bound for it. It sounds reasonable to
279
292
// also generate trait bound for qualified associated type `<T as Trait>::Assoc`, but rustc
@@ -301,7 +314,7 @@ fn parse_adt(
301
314
. map ( |it| mbe:: syntax_node_to_token_tree ( it. syntax ( ) , tm, call_site) )
302
315
. collect ( ) ;
303
316
let name_token = name_to_token ( tm, name) ?;
304
- Ok ( BasicAdtInfo { name : name_token, shape, param_types, associated_types } )
317
+ Ok ( BasicAdtInfo { name : name_token, shape, param_types, where_clause , associated_types } )
305
318
}
306
319
307
320
fn name_to_token (
@@ -366,7 +379,8 @@ fn expand_simple_derive(
366
379
}
367
380
} ;
368
381
let trait_body = make_trait_body ( & info) ;
369
- let mut where_block = vec ! [ ] ;
382
+ let mut where_block: Vec < _ > =
383
+ info. where_clause . into_iter ( ) . map ( |w| quote ! { invoc_span => #w , } ) . collect ( ) ;
370
384
let ( params, args) : ( Vec < _ > , Vec < _ > ) = info
371
385
. param_types
372
386
. into_iter ( )
0 commit comments