@@ -199,9 +199,10 @@ pub enum InvocationKind {
199
199
span : Span ,
200
200
} ,
201
201
Attr {
202
- attr : Option < ast:: Attribute > ,
203
- traits : Vec < Path > ,
202
+ attr : ast:: Attribute ,
204
203
item : Annotatable ,
204
+ // Required for resolving derive helper attributes.
205
+ derives : Vec < Path > ,
205
206
// We temporarily report errors for attribute macros placed after derives
206
207
after_derive : bool ,
207
208
} ,
@@ -210,15 +211,22 @@ pub enum InvocationKind {
210
211
item : Annotatable ,
211
212
item_with_markers : Annotatable ,
212
213
} ,
214
+ /// "Invocation" that contains all derives from an item,
215
+ /// broken into multiple `Derive` invocations when expanded.
216
+ /// FIXME: Find a way to remove it.
217
+ DeriveContainer {
218
+ derives : Vec < Path > ,
219
+ item : Annotatable ,
220
+ } ,
213
221
}
214
222
215
223
impl Invocation {
216
224
pub fn span ( & self ) -> Span {
217
- match self . kind {
218
- InvocationKind :: Bang { span, .. } => span,
219
- InvocationKind :: Attr { attr : Some ( ref attr ) , .. } => attr. span ,
220
- InvocationKind :: Attr { attr : None , .. } => DUMMY_SP ,
221
- InvocationKind :: Derive { ref path , .. } => path . span ,
225
+ match & self . kind {
226
+ InvocationKind :: Bang { span, .. } => * span,
227
+ InvocationKind :: Attr { attr, .. } => attr. span ,
228
+ InvocationKind :: Derive { path , .. } => path . span ,
229
+ InvocationKind :: DeriveContainer { item , .. } => item . span ( ) ,
222
230
}
223
231
}
224
232
}
@@ -329,7 +337,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
329
337
let ( expanded_fragment, new_invocations) = if let Some ( ext) = ext {
330
338
let fragment = self . expand_invoc ( invoc, & ext. kind ) ;
331
339
self . collect_invocations ( fragment, & [ ] )
332
- } else if let InvocationKind :: Attr { attr : None , traits, item, .. } = invoc. kind {
340
+ } else if let InvocationKind :: DeriveContainer { derives : traits, item } = invoc. kind {
333
341
if !item. derive_allowed ( ) {
334
342
let attr = attr:: find_by_name ( item. attrs ( ) , sym:: derive)
335
343
. expect ( "`derive` attribute should exist" ) ;
@@ -522,7 +530,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
522
530
}
523
531
_ => unreachable ! ( )
524
532
}
525
- InvocationKind :: Attr { attr : Some ( attr ) , mut item, .. } => match ext {
533
+ InvocationKind :: Attr { attr, mut item, .. } => match ext {
526
534
SyntaxExtensionKind :: Attr ( expander) => {
527
535
self . gate_proc_macro_attr_item ( span, & item) ;
528
536
let item_tok = TokenTree :: token ( token:: Interpolated ( Lrc :: new ( match item {
@@ -578,7 +586,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
578
586
}
579
587
_ => unreachable ! ( )
580
588
}
581
- _ => unreachable ! ( )
589
+ InvocationKind :: DeriveContainer { .. } => unreachable ! ( )
582
590
}
583
591
}
584
592
@@ -805,10 +813,10 @@ struct InvocationCollector<'a, 'b> {
805
813
impl < ' a , ' b > InvocationCollector < ' a , ' b > {
806
814
fn collect ( & mut self , fragment_kind : AstFragmentKind , kind : InvocationKind ) -> AstFragment {
807
815
// Expansion info for all the collected invocations is set upon their resolution,
808
- // with exception of the " derive container" case which is not resolved and can get
816
+ // with exception of the derive container case which is not resolved and can get
809
817
// its expansion info immediately.
810
818
let expn_info = match & kind {
811
- InvocationKind :: Attr { attr : None , item, .. } => Some ( ExpnInfo :: default (
819
+ InvocationKind :: DeriveContainer { item, .. } => Some ( ExpnInfo :: default (
812
820
ExpnKind :: Macro ( MacroKind :: Attr , sym:: derive) ,
813
821
item. span ( ) , self . cx . parse_sess . edition ,
814
822
) ) ,
@@ -833,12 +841,15 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
833
841
834
842
fn collect_attr ( & mut self ,
835
843
attr : Option < ast:: Attribute > ,
836
- traits : Vec < Path > ,
844
+ derives : Vec < Path > ,
837
845
item : Annotatable ,
838
846
kind : AstFragmentKind ,
839
847
after_derive : bool )
840
848
-> AstFragment {
841
- self . collect ( kind, InvocationKind :: Attr { attr, traits, item, after_derive } )
849
+ self . collect ( kind, match attr {
850
+ Some ( attr) => InvocationKind :: Attr { attr, item, derives, after_derive } ,
851
+ None => InvocationKind :: DeriveContainer { derives, item } ,
852
+ } )
842
853
}
843
854
844
855
fn find_attr_invoc ( & self , attrs : & mut Vec < ast:: Attribute > , after_derive : & mut bool )
0 commit comments