@@ -345,15 +345,18 @@ pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>)
345
345
/// This method helps to extract all the type parameters referenced from a
346
346
/// type. For a type parameter `<T>`, it looks for either a `TyPath` that
347
347
/// is not global and starts with `T`, or a `TyQPath`.
348
- fn find_type_parameters ( ty : & ast:: Ty , ty_param_names : & [ ast:: Name ] ) -> Vec < P < ast:: Ty > > {
348
+ fn find_type_parameters ( ty : & ast:: Ty , ty_param_names : & [ ast:: Name ] , span : Span , cx : & ExtCtxt )
349
+ -> Vec < P < ast:: Ty > > {
349
350
use syntax:: visit;
350
351
351
- struct Visitor < ' a > {
352
+ struct Visitor < ' a , ' b : ' a > {
353
+ cx : & ' a ExtCtxt < ' b > ,
354
+ span : Span ,
352
355
ty_param_names : & ' a [ ast:: Name ] ,
353
356
types : Vec < P < ast:: Ty > > ,
354
357
}
355
358
356
- impl < ' a > visit:: Visitor for Visitor < ' a > {
359
+ impl < ' a , ' b > visit:: Visitor for Visitor < ' a , ' b > {
357
360
fn visit_ty ( & mut self , ty : & ast:: Ty ) {
358
361
match ty. node {
359
362
ast:: TyKind :: Path ( _, ref path) if !path. global => {
@@ -371,11 +374,18 @@ fn find_type_parameters(ty: &ast::Ty, ty_param_names: &[ast::Name]) -> Vec<P<ast
371
374
372
375
visit:: walk_ty ( self , ty)
373
376
}
377
+
378
+ fn visit_mac ( & mut self , mac : & ast:: Mac ) {
379
+ let span = Span { expn_id : self . span . expn_id , ..mac. span } ;
380
+ self . cx . span_err ( span, "`derive` cannot be used on items with type macros" ) ;
381
+ }
374
382
}
375
383
376
384
let mut visitor = Visitor {
377
385
ty_param_names : ty_param_names,
378
386
types : Vec :: new ( ) ,
387
+ span : span,
388
+ cx : cx,
379
389
} ;
380
390
381
391
visit:: Visitor :: visit_ty ( & mut visitor, ty) ;
@@ -556,7 +566,7 @@ impl<'a> TraitDef<'a> {
556
566
557
567
let mut processed_field_types = HashSet :: new ( ) ;
558
568
for field_ty in field_tys {
559
- let tys = find_type_parameters ( & field_ty, & ty_param_names) ;
569
+ let tys = find_type_parameters ( & field_ty, & ty_param_names, self . span , cx ) ;
560
570
561
571
for ty in tys {
562
572
// if we have already handled this type, skip it
0 commit comments