@@ -301,6 +301,8 @@ pub enum InvocationKind {
301301    } , 
302302    Attr  { 
303303        attr :  ast:: Attribute , 
304+         // Re-insertion position for inert attributes. 
305+         pos :  usize , 
304306        item :  Annotatable , 
305307        // Required for resolving derive helper attributes. 
306308        derives :  Vec < Path > , 
@@ -690,7 +692,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
690692                } 
691693                _ => unreachable ! ( ) , 
692694            } , 
693-             InvocationKind :: Attr  {  attr,  mut  item,  derives }  => match  ext { 
695+             InvocationKind :: Attr  {  attr,  pos ,   mut  item,  derives }  => match  ext { 
694696                SyntaxExtensionKind :: Attr ( expander)  => { 
695697                    self . gate_proc_macro_input ( & item) ; 
696698                    self . gate_proc_macro_attr_item ( span,  & item) ; 
@@ -721,7 +723,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
721723                                ExpandResult :: Retry ( item)  => { 
722724                                    // Reassemble the original invocation for retrying. 
723725                                    return  ExpandResult :: Retry ( Invocation  { 
724-                                         kind :  InvocationKind :: Attr  {  attr,  item,  derives } , 
726+                                         kind :  InvocationKind :: Attr  {  attr,  pos ,   item,  derives } , 
725727                                        ..invoc
726728                                    } ) ; 
727729                                } 
@@ -739,7 +741,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
739741                    if  * mark_used { 
740742                        self . cx . sess . mark_attr_used ( & attr) ; 
741743                    } 
742-                     item. visit_attrs ( |attrs| attrs. push ( attr) ) ; 
744+                     item. visit_attrs ( |attrs| attrs. insert ( pos ,   attr) ) ; 
743745                    fragment_kind. expect_from_annotatables ( iter:: once ( item) ) 
744746                } 
745747                _ => unreachable ! ( ) , 
@@ -1000,17 +1002,20 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
10001002
10011003    fn  collect_attr ( 
10021004        & mut  self , 
1003-         ( attr,  derives) :  ( ast:: Attribute ,  Vec < Path > ) , 
1005+         ( attr,  pos ,   derives) :  ( ast:: Attribute ,   usize ,  Vec < Path > ) , 
10041006        item :  Annotatable , 
10051007        kind :  AstFragmentKind , 
10061008    )  -> AstFragment  { 
1007-         self . collect ( kind,  InvocationKind :: Attr  {  attr,  item,  derives } ) 
1009+         self . collect ( kind,  InvocationKind :: Attr  {  attr,  pos ,   item,  derives } ) 
10081010    } 
10091011
10101012    /// If `item` is an attribute invocation, remove the attribute and return it together with 
1011- /// derives following it. We have to collect the derives in order to resolve legacy derive 
1012- /// helpers (helpers written before derives that introduce them). 
1013- fn  take_first_attr ( & mut  self ,  item :  & mut  impl  HasAttrs )  -> Option < ( ast:: Attribute ,  Vec < Path > ) >  { 
1013+ /// its position and derives following it. We have to collect the derives in order to resolve 
1014+ /// legacy derive helpers (helpers written before derives that introduce them). 
1015+ fn  take_first_attr ( 
1016+         & mut  self , 
1017+         item :  & mut  impl  HasAttrs , 
1018+     )  -> Option < ( ast:: Attribute ,  usize ,  Vec < Path > ) >  { 
10141019        let  mut  attr = None ; 
10151020
10161021        item. visit_attrs ( |attrs| { 
@@ -1033,7 +1038,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
10331038                        } ) 
10341039                        . collect ( ) ; 
10351040
1036-                     ( attr,  following_derives) 
1041+                     ( attr,  attr_pos ,   following_derives) 
10371042                } ) 
10381043        } ) ; 
10391044
0 commit comments