Repository: dtolnay/syn
Pull request #1322 (2023-01-23 07:33:17)

Delete Item::Macro2
This syntax does not appear to be on track for stabilization these days.


Patch:
diff --git a/src/gen/clone.rs b/src/gen/clone.rs
index 06ab49c6..0b3b1e8b 100644
--- a/src/gen/clone.rs
+++ b/src/gen/clone.rs
@@ -1030,7 +1030,6 @@ impl Clone for Item {
             Item::ForeignMod(v0) => Item::ForeignMod(v0.clone()),
             Item::Impl(v0) => Item::Impl(v0.clone()),
             Item::Macro(v0) => Item::Macro(v0.clone()),
-            Item::Macro2(v0) => Item::Macro2(v0.clone()),
             Item::Mod(v0) => Item::Mod(v0.clone()),
             Item::Static(v0) => Item::Static(v0.clone()),
             Item::Struct(v0) => Item::Struct(v0.clone()),
@@ -1145,19 +1144,6 @@ impl Clone for ItemMacro {
 }
 #[cfg(feature = "full")]
 #[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))]
-impl Clone for ItemMacro2 {
-    fn clone(&self) -> Self {
-        ItemMacro2 {
-            attrs: self.attrs.clone(),
-            vis: self.vis.clone(),
-            macro_token: self.macro_token.clone(),
-            ident: self.ident.clone(),
-            rules: self.rules.clone(),
-        }
-    }
-}
-#[cfg(feature = "full")]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))]
 impl Clone for ItemMod {
     fn clone(&self) -> Self {
         ItemMod {
diff --git a/src/gen/debug.rs b/src/gen/debug.rs
index bde6a00f..bc0a1f91 100644
--- a/src/gen/debug.rs
+++ b/src/gen/debug.rs
@@ -1460,11 +1460,6 @@ impl Debug for Item {
                 formatter.field(v0);
                 formatter.finish()
             }
-            Item::Macro2(v0) => {
-                let mut formatter = formatter.debug_tuple("Macro2");
-                formatter.field(v0);
-                formatter.finish()
-            }
             Item::Mod(v0) => {
                 let mut formatter = formatter.debug_tuple("Mod");
                 formatter.field(v0);
@@ -1615,19 +1610,6 @@ impl Debug for ItemMacro {
 }
 #[cfg(feature = "full")]
 #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
-impl Debug for ItemMacro2 {
-    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
-        let mut formatter = formatter.debug_struct("ItemMacro2");
-        formatter.field("attrs", &self.attrs);
-        formatter.field("vis", &self.vis);
-        formatter.field("macro_token", &self.macro_token);
-        formatter.field("ident", &self.ident);
-        formatter.field("rules", &self.rules);
-        formatter.finish()
-    }
-}
-#[cfg(feature = "full")]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
 impl Debug for ItemMod {
     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
         let mut formatter = formatter.debug_struct("ItemMod");
diff --git a/src/gen/eq.rs b/src/gen/eq.rs
index 3787ebd8..5251693c 100644
--- a/src/gen/eq.rs
+++ b/src/gen/eq.rs
@@ -1000,7 +1000,6 @@ impl PartialEq for Item {
             (Item::ForeignMod(self0), Item::ForeignMod(other0)) => self0 == other0,
             (Item::Impl(self0), Item::Impl(other0)) => self0 == other0,
             (Item::Macro(self0), Item::Macro(other0)) => self0 == other0,
-            (Item::Macro2(self0), Item::Macro2(other0)) => self0 == other0,
             (Item::Mod(self0), Item::Mod(other0)) => self0 == other0,
             (Item::Static(self0), Item::Static(other0)) => self0 == other0,
             (Item::Struct(self0), Item::Struct(other0)) => self0 == other0,
@@ -1096,17 +1095,6 @@ impl PartialEq for ItemMacro {
 }
 #[cfg(feature = "full")]
 #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
-impl Eq for ItemMacro2 {}
-#[cfg(feature = "full")]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
-impl PartialEq for ItemMacro2 {
-    fn eq(&self, other: &Self) -> bool {
-        self.attrs == other.attrs && self.vis == other.vis && self.ident == other.ident
-            && TokenStreamHelper(&self.rules) == TokenStreamHelper(&other.rules)
-    }
-}
-#[cfg(feature = "full")]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
 impl Eq for ItemMod {}
 #[cfg(feature = "full")]
 #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
diff --git a/src/gen/fold.rs b/src/gen/fold.rs
index e013219a..c689a7db 100644
--- a/src/gen/fold.rs
+++ b/src/gen/fold.rs
@@ -382,10 +382,6 @@ pub trait Fold {
         fold_item_macro(self, i)
     }
     #[cfg(feature = "full")]
-    fn fold_item_macro2(&mut self, i: ItemMacro2) -> ItemMacro2 {
-        fold_item_macro2(self, i)
-    }
-    #[cfg(feature = "full")]
     fn fold_item_mod(&mut self, i: ItemMod) -> ItemMod {
         fold_item_mod(self, i)
     }
@@ -1907,7 +1903,6 @@ where
         }
         Item::Impl(_binding_0) => Item::Impl(f.fold_item_impl(_binding_0)),
         Item::Macro(_binding_0) => Item::Macro(f.fold_item_macro(_binding_0)),
-        Item::Macro2(_binding_0) => Item::Macro2(f.fold_item_macro2(_binding_0)),
         Item::Mod(_binding_0) => Item::Mod(f.fold_item_mod(_binding_0)),
         Item::Static(_binding_0) => Item::Static(f.fold_item_static(_binding_0)),
         Item::Struct(_binding_0) => Item::Struct(f.fold_item_struct(_binding_0)),
@@ -2032,19 +2027,6 @@ where
     }
 }
 #[cfg(feature = "full")]
-pub fn fold_item_macro2<F>(f: &mut F, node: ItemMacro2) -> ItemMacro2
-where
-    F: Fold + ?Sized,
-{
-    ItemMacro2 {
-        attrs: FoldHelper::lift(node.attrs, |it| f.fold_attribute(it)),
-        vis: f.fold_visibility(node.vis),
-        macro_token: Token![macro](tokens_helper(f, &node.macro_token.span)),
-        ident: f.fold_ident(node.ident),
-        rules: node.rules,
-    }
-}
-#[cfg(feature = "full")]
 pub fn fold_item_mod<F>(f: &mut F, node: ItemMod) -> ItemMod
 where
     F: Fold + ?Sized,
diff --git a/src/gen/hash.rs b/src/gen/hash.rs
index e6a08963..7a1cae09 100644
--- a/src/gen/hash.rs
+++ b/src/gen/hash.rs
@@ -1356,44 +1356,40 @@ impl Hash for Item {
                 state.write_u8(6u8);
                 v0.hash(state);
             }
-            Item::Macro2(v0) => {
-                state.write_u8(7u8);
-                v0.hash(state);
-            }
             Item::Mod(v0) => {
-                state.write_u8(8u8);
+                state.write_u8(7u8);
                 v0.hash(state);
             }
             Item::Static(v0) => {
-                state.write_u8(9u8);
+                state.write_u8(8u8);
                 v0.hash(state);
             }
             Item::Struct(v0) => {
-                state.write_u8(10u8);
+                state.write_u8(9u8);
                 v0.hash(state);
             }
             Item::Trait(v0) => {
-                state.write_u8(11u8);
+                state.write_u8(10u8);
                 v0.hash(state);
             }
             Item::TraitAlias(v0) => {
-                state.write_u8(12u8);
+                state.write_u8(11u8);
                 v0.hash(state);
             }
             Item::Type(v0) => {
-                state.write_u8(13u8);
+                state.write_u8(12u8);
                 v0.hash(state);
             }
             Item::Union(v0) => {
-                state.write_u8(14u8);
+                state.write_u8(13u8);
                 v0.hash(state);
             }
             Item::Use(v0) => {
-                state.write_u8(15u8);
+                state.write_u8(14u8);
                 v0.hash(state);
             }
             Item::Verbatim(v0) => {
-                state.write_u8(16u8);
+                state.write_u8(15u8);
                 TokenStreamHelper(v0).hash(state);
             }
         }
@@ -1496,19 +1492,6 @@ impl Hash for ItemMacro {
 }
 #[cfg(feature = "full")]
 #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
-impl Hash for ItemMacro2 {
-    fn hash<H>(&self, state: &mut H)
-    where
-        H: Hasher,
-    {
-        self.attrs.hash(state);
-        self.vis.hash(state);
-        self.ident.hash(state);
-        TokenStreamHelper(&self.rules).hash(state);
-    }
-}
-#[cfg(feature = "full")]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
 impl Hash for ItemMod {
     fn hash<H>(&self, state: &mut H)
     where
diff --git a/src/gen/visit.rs b/src/gen/visit.rs
index 56492b09..4390396e 100644
--- a/src/gen/visit.rs
+++ b/src/gen/visit.rs
@@ -384,10 +384,6 @@ pub trait Visit<'ast> {
         visit_item_macro(self, i);
     }
     #[cfg(feature = "full")]
-    fn visit_item_macro2(&mut self, i: &'ast ItemMacro2) {
-        visit_item_macro2(self, i);
-    }
-    #[cfg(feature = "full")]
     fn visit_item_mod(&mut self, i: &'ast ItemMod) {
         visit_item_mod(self, i);
     }
@@ -2127,9 +2123,6 @@ where
         Item::Macro(_binding_0) => {
             v.visit_item_macro(_binding_0);
         }
-        Item::Macro2(_binding_0) => {
-            v.visit_item_macro2(_binding_0);
-        }
         Item::Mod(_binding_0) => {
             v.visit_item_mod(_binding_0);
         }
@@ -2287,19 +2280,6 @@ where
     }
 }
 #[cfg(feature = "full")]
-pub fn visit_item_macro2<'ast, V>(v: &mut V, node: &'ast ItemMacro2)
-where
-    V: Visit<'ast> + ?Sized,
-{
-    for it in &node.attrs {
-        v.visit_attribute(it);
-    }
-    v.visit_visibility(&node.vis);
-    tokens_helper(v, &node.macro_token.span);
-    v.visit_ident(&node.ident);
-    skip!(node.rules);
-}
-#[cfg(feature = "full")]
 pub fn visit_item_mod<'ast, V>(v: &mut V, node: &'ast ItemMod)
 where
     V: Visit<'ast> + ?Sized,
diff --git a/src/gen/visit_mut.rs b/src/gen/visit_mut.rs
index 75685f57..1704d05d 100644
--- a/src/gen/visit_mut.rs
+++ b/src/gen/visit_mut.rs
@@ -385,10 +385,6 @@ pub trait VisitMut {
         visit_item_macro_mut(self, i);
     }
     #[cfg(feature = "full")]
-    fn visit_item_macro2_mut(&mut self, i: &mut ItemMacro2) {
-        visit_item_macro2_mut(self, i);
-    }
-    #[cfg(feature = "full")]
     fn visit_item_mod_mut(&mut self, i: &mut ItemMod) {
         visit_item_mod_mut(self, i);
     }
@@ -2130,9 +2126,6 @@ where
         Item::Macro(_binding_0) => {
             v.visit_item_macro_mut(_binding_0);
         }
-        Item::Macro2(_binding_0) => {
-            v.visit_item_macro2_mut(_binding_0);
-        }
         Item::Mod(_binding_0) => {
             v.visit_item_mod_mut(_binding_0);
         }
@@ -2290,19 +2283,6 @@ where
     }
 }
 #[cfg(feature = "full")]
-pub fn visit_item_macro2_mut<V>(v: &mut V, node: &mut ItemMacro2)
-where
-    V: VisitMut + ?Sized,
-{
-    for it in &mut node.attrs {
-        v.visit_attribute_mut(it);
-    }
-    v.visit_visibility_mut(&mut node.vis);
-    tokens_helper(v, &mut node.macro_token.span);
-    v.visit_ident_mut(&mut node.ident);
-    skip!(node.rules);
-}
-#[cfg(feature = "full")]
 pub fn visit_item_mod_mut<V>(v: &mut V, node: &mut ItemMod)
 where
     V: VisitMut + ?Sized,
diff --git a/src/item.rs b/src/item.rs
index bc0606c6..7df3c613 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -40,9 +40,6 @@ ast_enum_of_structs! {
         /// A macro invocation, which includes `macro_rules!` definitions.
         Macro(ItemMacro),
 
-        /// A 2.0-style declarative macro introduced by the `macro` keyword.
-        Macro2(ItemMacro2),
-
         /// A module or module declaration: `mod m` or `mod m { ... }`.
         Mod(ItemMod),
 
@@ -188,18 +185,6 @@ ast_struct! {
     }
 }
 
-ast_struct! {
-    /// A 2.0-style declarative macro introduced by the `macro` keyword.
-    #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
-    pub struct ItemMacro2 {
-        pub attrs: Vec<Attribute>,
-        pub vis: Visibility,
-        pub macro_token: Token![macro],
-        pub ident: Ident,
-        pub rules: TokenStream,
-    }
-}
-
 ast_struct! {
     /// A module or module declaration: `mod m` or `mod m { ... }`.
     #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))]
@@ -329,7 +314,6 @@ impl Item {
             | Item::ForeignMod(ItemForeignMod { attrs, .. })
             | Item::Impl(ItemImpl { attrs, .. })
             | Item::Macro(ItemMacro { attrs, .. })
-            | Item::Macro2(ItemMacro2 { attrs, .. })
             | Item::Mod(ItemMod { attrs, .. })
             | Item::Static(ItemStatic { attrs, .. })
             | Item::Struct(ItemStruct { attrs, .. })
@@ -870,8 +854,8 @@ pub mod parsing {
     use crate::parse::discouraged::Speculative;
     use crate::parse::{Parse, ParseBuffer, ParseStream, Result};
     use crate::token::Brace;
-    use proc_macro2::{Delimiter, Group, Punct, Spacing, TokenTree};
-    use std::iter::{self, FromIterator};
+    use proc_macro2::{Punct, Spacing, TokenTree};
+    use std::iter::FromIterator;
 
     crate::custom_keyword!(macro_rules);
 
@@ -1034,7 +1018,8 @@ pub mod parsing {
                     Ok(Item::Verbatim(verbatim::between(begin, input)))
                 }
             } else if lookahead.peek(Token![macro]) {
-                input.parse().map(Item::Macro2)
+                input.advance_to(&ahead);
+                parse_macro2(begin, vis, input)
             } else if vis.is_inherited()
                 && (lookahead.peek(Ident)
                     || lookahead.peek(Token![self])
@@ -1167,45 +1152,27 @@ pub mod parsing {
         }
     }
 
-    #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
-    impl Parse for ItemMacro2 {
-        fn parse(input: ParseStream) -> Result<Self> {
-            let attrs = input.call(Attribute::parse_outer)?;
-            let vis: Visibility = input.parse()?;
-            let macro_token: Token![macro] = input.parse()?;
-            let ident: Ident = input.parse()?;
-            let mut rules = TokenStream::new();
-
-            let mut lookahead = input.lookahead1();
-            if lookahead.peek(token::Paren) {
-                let paren_content;
-                let paren_token = parenthesized!(paren_content in input);
-                let args: TokenStream = paren_content.parse()?;
-                let mut args = Group::new(Delimiter::Parenthesis, args);
-                args.set_span(paren_token.span);
-                rules.extend(iter::once(TokenTree::Group(args)));
-                lookahead = input.lookahead1();
-            }
+    fn parse_macro2(begin: ParseBuffer, _vis: Visibility, input: ParseStream) -> Result<Item> {
+        input.parse::<Token![macro]>()?;
+        input.parse::<Ident>()?;
 
-            if lookahead.peek(token::Brace) {
-                let brace_content;
-                let brace_token = braced!(brace_content in input);
-                let body: TokenStream = brace_content.parse()?;
-                let mut body = Group::new(Delimiter::Brace, body);
-                body.set_span(brace_token.span);
-                rules.extend(iter::once(TokenTree::Group(body)));
-            } else {
-                return Err(lookahead.error());
-            }
+        let mut lookahead = input.lookahead1();
+        if lookahead.peek(token::Paren) {
+            let paren_content;
+            parenthesized!(paren_content in input);
+            paren_content.parse::<TokenStream>()?;
+            lookahead = input.lookahead1();
+        }
 
-            Ok(ItemMacro2 {
-                attrs,
-                vis,
-                macro_token,
-                ident,
-                rules,
-            })
+        if lookahead.peek(token::Brace) {
+            let brace_content;
+            braced!(brace_content in input);
+            brace_content.parse::<TokenStream>()?;
+        } else {
+            return Err(lookahead.error());
         }
+
+        Ok(Item::Verbatim(verbatim::between(begin, input)))
     }
 
     #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
@@ -2963,17 +2930,6 @@ mod printing {
         }
     }
 
-    #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
-    impl ToTokens for ItemMacro2 {
-        fn to_tokens(&self, tokens: &mut TokenStream) {
-            tokens.append_all(self.attrs.outer());
-            self.vis.to_tokens(tokens);
-            self.macro_token.to_tokens(tokens);
-            self.ident.to_tokens(tokens);
-            self.rules.to_tokens(tokens);
-        }
-    }
-
     #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
     impl ToTokens for UsePath {
         fn to_tokens(&self, tokens: &mut TokenStream) {
diff --git a/src/lib.rs b/src/lib.rs
index 9ca8e520..596e2105 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -385,10 +385,10 @@ mod item;
 pub use crate::item::{
     FnArg, ForeignItem, ForeignItemFn, ForeignItemMacro, ForeignItemStatic, ForeignItemType,
     ImplItem, ImplItemConst, ImplItemMacro, ImplItemMethod, ImplItemType, Item, ItemConst,
-    ItemEnum, ItemExternCrate, ItemFn, ItemForeignMod, ItemImpl, ItemMacro, ItemMacro2, ItemMod,
-    ItemStatic, ItemStruct, ItemTrait, ItemTraitAlias, ItemType, ItemUnion, ItemUse, Receiver,
-    Signature, TraitItem, TraitItemConst, TraitItemMacro, TraitItemMethod, TraitItemType, UseGlob,
-    UseGroup, UseName, UsePath, UseRename, UseTree,
+    ItemEnum, ItemExternCrate, ItemFn, ItemForeignMod, ItemImpl, ItemMacro, ItemMod, ItemStatic,
+    ItemStruct, ItemTrait, ItemTraitAlias, ItemType, ItemUnion, ItemUse, Receiver, Signature,
+    TraitItem, TraitItemConst, TraitItemMacro, TraitItemMethod, TraitItemType, UseGlob, UseGroup,
+    UseName, UsePath, UseRename, UseTree,
 };
 
 mod lifetime;
diff --git a/syn.json b/syn.json
index fcb69a99..71c8ef34 100644
--- a/syn.json
+++ b/syn.json
@@ -2554,11 +2554,6 @@
             "syn": "ItemMacro"
           }
         ],
-        "Macro2": [
-          {
-            "syn": "ItemMacro2"
-          }
-        ],
         "Mod": [
           {
             "syn": "ItemMod"
@@ -2871,33 +2866,6 @@
         }
       }
     },
-    {
-      "ident": "ItemMacro2",
-      "features": {
-        "any": [
-          "full"
-        ]
-      },
-      "fields": {
-        "attrs": {
-          "vec": {
-            "syn": "Attribute"
-          }
-        },
-        "vis": {
-          "syn": "Visibility"
-        },
-        "macro_token": {
-          "token": "Macro"
-        },
-        "ident": {
-          "proc_macro2": "Ident"
-        },
-        "rules": {
-          "proc_macro2": "TokenStream"
-        }
-      }
-    },
     {
       "ident": "ItemMod",
       "features": {


Test patch:
diff --git a/tests/debug/gen.rs b/tests/debug/gen.rs
index 867b37bb..ddcdc439 100644
--- a/tests/debug/gen.rs
+++ b/tests/debug/gen.rs
@@ -2798,16 +2798,6 @@ impl Debug for Lite<syn::Item> {
                 }
                 formatter.finish()
             }
-            syn::Item::Macro2(_val) => {
-                let mut formatter = formatter.debug_struct("Item::Macro2");
-                if !_val.attrs.is_empty() {
-                    formatter.field("attrs", Lite(&_val.attrs));
-                }
-                formatter.field("vis", Lite(&_val.vis));
-                formatter.field("ident", Lite(&_val.ident));
-                formatter.field("rules", Lite(&_val.rules));
-                formatter.finish()
-            }
             syn::Item::Mod(_val) => {
                 let mut formatter = formatter.debug_struct("Item::Mod");
                 if !_val.attrs.is_empty() {
@@ -3214,19 +3204,6 @@ impl Debug for Lite<syn::ItemMacro> {
         formatter.finish()
     }
 }
-impl Debug for Lite<syn::ItemMacro2> {
-    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
-        let _val = &self.value;
-        let mut formatter = formatter.debug_struct("ItemMacro2");
-        if !_val.attrs.is_empty() {
-            formatter.field("attrs", Lite(&_val.attrs));
-        }
-        formatter.field("vis", Lite(&_val.vis));
-        formatter.field("ident", Lite(&_val.ident));
-        formatter.field("rules", Lite(&_val.rules));
-        formatter.finish()
-    }
-}
 impl Debug for Lite<syn::ItemMod> {
     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
         let _val = &self.value;