@@ -199,9 +199,10 @@ pub enum InvocationKind {
199199 span : Span ,
200200 } ,
201201 Attr {
202- attr : Option < ast:: Attribute > ,
203- traits : Vec < Path > ,
202+ attr : ast:: Attribute ,
204203 item : Annotatable ,
204+ // Required for resolving derive helper attributes.
205+ derives : Vec < Path > ,
205206 // We temporarily report errors for attribute macros placed after derives
206207 after_derive : bool ,
207208 } ,
@@ -210,15 +211,22 @@ pub enum InvocationKind {
210211 item : Annotatable ,
211212 item_with_markers : Annotatable ,
212213 } ,
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+ } ,
213221}
214222
215223impl Invocation {
216224 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 ( ) ,
222230 }
223231 }
224232}
@@ -329,7 +337,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
329337 let ( expanded_fragment, new_invocations) = if let Some ( ext) = ext {
330338 let fragment = self . expand_invoc ( invoc, & ext. kind ) ;
331339 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 {
333341 if !item. derive_allowed ( ) {
334342 let attr = attr:: find_by_name ( item. attrs ( ) , sym:: derive)
335343 . expect ( "`derive` attribute should exist" ) ;
@@ -522,7 +530,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
522530 }
523531 _ => unreachable ! ( )
524532 }
525- InvocationKind :: Attr { attr : Some ( attr ) , mut item, .. } => match ext {
533+ InvocationKind :: Attr { attr, mut item, .. } => match ext {
526534 SyntaxExtensionKind :: Attr ( expander) => {
527535 self . gate_proc_macro_attr_item ( span, & item) ;
528536 let item_tok = TokenTree :: token ( token:: Interpolated ( Lrc :: new ( match item {
@@ -578,7 +586,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
578586 }
579587 _ => unreachable ! ( )
580588 }
581- _ => unreachable ! ( )
589+ InvocationKind :: DeriveContainer { .. } => unreachable ! ( )
582590 }
583591 }
584592
@@ -805,10 +813,10 @@ struct InvocationCollector<'a, 'b> {
805813impl < ' a , ' b > InvocationCollector < ' a , ' b > {
806814 fn collect ( & mut self , fragment_kind : AstFragmentKind , kind : InvocationKind ) -> AstFragment {
807815 // 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
809817 // its expansion info immediately.
810818 let expn_info = match & kind {
811- InvocationKind :: Attr { attr : None , item, .. } => Some ( ExpnInfo :: default (
819+ InvocationKind :: DeriveContainer { item, .. } => Some ( ExpnInfo :: default (
812820 ExpnKind :: Macro ( MacroKind :: Attr , sym:: derive) ,
813821 item. span ( ) , self . cx . parse_sess . edition ,
814822 ) ) ,
@@ -833,12 +841,15 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
833841
834842 fn collect_attr ( & mut self ,
835843 attr : Option < ast:: Attribute > ,
836- traits : Vec < Path > ,
844+ derives : Vec < Path > ,
837845 item : Annotatable ,
838846 kind : AstFragmentKind ,
839847 after_derive : bool )
840848 -> 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+ } )
842853 }
843854
844855 fn find_attr_invoc ( & self , attrs : & mut Vec < ast:: Attribute > , after_derive : & mut bool )
0 commit comments