@@ -451,28 +451,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
451
451
_ => unreachable ! ( ) ,
452
452
} ;
453
453
if !item. derive_allowed ( ) {
454
- let attr = attr:: find_by_name ( item. attrs ( ) , sym:: derive)
455
- . expect ( "`derive` attribute should exist" ) ;
456
- let span = attr. span ;
457
- let mut err = self . cx . struct_span_err (
458
- span,
459
- "`derive` may only be applied to structs, enums and unions" ,
460
- ) ;
461
- if let ast:: AttrStyle :: Inner = attr. style {
462
- let trait_list = derives
463
- . iter ( )
464
- . map ( |t| pprust:: path_to_string ( t) )
465
- . collect :: < Vec < _ > > ( ) ;
466
- let suggestion = format ! ( "#[derive({})]" , trait_list. join( ", " ) ) ;
467
- err. span_suggestion (
468
- span,
469
- "try an outer attribute" ,
470
- suggestion,
471
- // We don't 𝑘𝑛𝑜𝑤 that the following item is an ADT
472
- Applicability :: MaybeIncorrect ,
473
- ) ;
474
- }
475
- err. emit ( ) ;
454
+ self . error_derive_forbidden_on_non_adt ( & derives, & item) ;
476
455
}
477
456
478
457
let mut item = self . fully_configure ( item) ;
@@ -521,6 +500,27 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
521
500
fragment_with_placeholders
522
501
}
523
502
503
+ fn error_derive_forbidden_on_non_adt ( & self , derives : & [ Path ] , item : & Annotatable ) {
504
+ let attr =
505
+ attr:: find_by_name ( item. attrs ( ) , sym:: derive) . expect ( "`derive` attribute should exist" ) ;
506
+ let span = attr. span ;
507
+ let mut err = self
508
+ . cx
509
+ . struct_span_err ( span, "`derive` may only be applied to structs, enums and unions" ) ;
510
+ if let ast:: AttrStyle :: Inner = attr. style {
511
+ let trait_list = derives. iter ( ) . map ( |t| pprust:: path_to_string ( t) ) . collect :: < Vec < _ > > ( ) ;
512
+ let suggestion = format ! ( "#[derive({})]" , trait_list. join( ", " ) ) ;
513
+ err. span_suggestion (
514
+ span,
515
+ "try an outer attribute" ,
516
+ suggestion,
517
+ // We don't 𝑘𝑛𝑜𝑤 that the following item is an ADT
518
+ Applicability :: MaybeIncorrect ,
519
+ ) ;
520
+ }
521
+ err. emit ( ) ;
522
+ }
523
+
524
524
fn resolve_imports ( & mut self ) {
525
525
if self . monotonic {
526
526
self . cx . resolver . resolve_imports ( ) ;
0 commit comments