@@ -65,10 +65,10 @@ impl Attribute {
6565 }
6666 }
6767
68- pub fn convert_normal_to_synthetic ( & mut self , synthetic_attr : SyntheticAttr ) {
68+ pub fn convert_normal_to_synthetic ( self , synthetic_attr : SyntheticAttr ) -> Attribute {
6969 match self . kind {
7070 AttrKind :: Normal ( ..) => {
71- self . kind = AttrKind :: Synthetic ( Box :: new ( synthetic_attr) ) ;
71+ Attribute { kind : AttrKind :: Synthetic ( Box :: new ( synthetic_attr) ) , .. self }
7272 }
7373 AttrKind :: Synthetic ( ..) | AttrKind :: DocComment ( ..) => unreachable ! ( ) ,
7474 }
@@ -141,8 +141,7 @@ impl AttributeExt for Attribute {
141141 . zip ( name)
142142 . all ( |( s, n) | s. args . is_none ( ) && s. ident . name == * n)
143143 }
144- AttrKind :: Synthetic ( ..) => false ,
145- AttrKind :: DocComment ( ..) => false ,
144+ AttrKind :: Synthetic ( ..) | AttrKind :: DocComment ( ..) => false ,
146145 }
147146 }
148147
@@ -168,8 +167,7 @@ impl AttributeExt for Attribute {
168167 fn meta_item_list ( & self ) -> Option < ThinVec < MetaItemInner > > {
169168 match & self . kind {
170169 AttrKind :: Normal ( normal) => normal. item . meta_item_list ( ) ,
171- AttrKind :: Synthetic ( ..) => None ,
172- AttrKind :: DocComment ( ..) => None ,
170+ AttrKind :: Synthetic ( ..) | AttrKind :: DocComment ( ..) => None ,
173171 }
174172 }
175173
@@ -280,8 +278,7 @@ impl Attribute {
280278 pub fn meta ( & self ) -> Option < MetaItem > {
281279 match & self . kind {
282280 AttrKind :: Normal ( normal) => normal. item . meta ( self . span ) ,
283- AttrKind :: Synthetic ( ..) => None ,
284- AttrKind :: DocComment ( ..) => None ,
281+ AttrKind :: Synthetic ( ..) | AttrKind :: DocComment ( ..) => None ,
285282 }
286283 }
287284
@@ -301,6 +298,7 @@ impl Attribute {
301298 . unwrap_or_else ( || panic ! ( "attribute is missing tokens: {self:?}" ) )
302299 . to_attr_token_stream ( )
303300 . to_token_trees ( ) ,
301+ // Empty tokens here ensures synthetic attributes are invisible to proc macros.
304302 AttrKind :: Synthetic ( ..) => vec ! [ ] ,
305303 AttrKind :: DocComment ( comment_kind, data) => vec ! [ TokenTree :: token_alone(
306304 token:: DocComment ( comment_kind, self . style, data) ,
0 commit comments