Repository: dtolnay/syn
Pull request #1347 (2023-01-31 03:00:16)

Delete VisPublic struct


Patch:
diff --git a/src/gen/clone.rs b/src/gen/clone.rs
index 7428e7c0..2e1996fc 100644
--- a/src/gen/clone.rs
+++ b/src/gen/clone.rs
@@ -2111,15 +2111,6 @@ impl Clone for Variant {
 }
 #[cfg(any(feature = "derive", feature = "full"))]
 #[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))]
-impl Clone for VisPublic {
-    fn clone(&self) -> Self {
-        VisPublic {
-            pub_token: self.pub_token.clone(),
-        }
-    }
-}
-#[cfg(any(feature = "derive", feature = "full"))]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))]
 impl Clone for VisRestricted {
     fn clone(&self) -> Self {
         VisRestricted {
diff --git a/src/gen/debug.rs b/src/gen/debug.rs
index a1e8b850..a5e68051 100644
--- a/src/gen/debug.rs
+++ b/src/gen/debug.rs
@@ -2876,15 +2876,6 @@ impl Debug for Variant {
 }
 #[cfg(any(feature = "derive", feature = "full"))]
 #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
-impl Debug for VisPublic {
-    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
-        let mut formatter = formatter.debug_struct("VisPublic");
-        formatter.field("pub_token", &self.pub_token);
-        formatter.finish()
-    }
-}
-#[cfg(any(feature = "derive", feature = "full"))]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
 impl Debug for VisRestricted {
     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
         let mut formatter = formatter.debug_struct("VisRestricted");
diff --git a/src/gen/eq.rs b/src/gen/eq.rs
index b2648a1e..6dfb96a8 100644
--- a/src/gen/eq.rs
+++ b/src/gen/eq.rs
@@ -2059,16 +2059,6 @@ impl PartialEq for Variant {
 }
 #[cfg(any(feature = "derive", feature = "full"))]
 #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
-impl Eq for VisPublic {}
-#[cfg(any(feature = "derive", feature = "full"))]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
-impl PartialEq for VisPublic {
-    fn eq(&self, _other: &Self) -> bool {
-        true
-    }
-}
-#[cfg(any(feature = "derive", feature = "full"))]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
 impl Eq for VisRestricted {}
 #[cfg(any(feature = "derive", feature = "full"))]
 #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
@@ -2085,7 +2075,7 @@ impl Eq for Visibility {}
 impl PartialEq for Visibility {
     fn eq(&self, other: &Self) -> bool {
         match (self, other) {
-            (Visibility::Public(self0), Visibility::Public(other0)) => self0 == other0,
+            (Visibility::Public(_), Visibility::Public(_)) => true,
             (Visibility::Restricted(self0), Visibility::Restricted(other0)) => {
                 self0 == other0
             }
diff --git a/src/gen/fold.rs b/src/gen/fold.rs
index 5c05d289..13b49dab 100644
--- a/src/gen/fold.rs
+++ b/src/gen/fold.rs
@@ -726,10 +726,6 @@ pub trait Fold {
         fold_variant(self, i)
     }
     #[cfg(any(feature = "derive", feature = "full"))]
-    fn fold_vis_public(&mut self, i: VisPublic) -> VisPublic {
-        fold_vis_public(self, i)
-    }
-    #[cfg(any(feature = "derive", feature = "full"))]
     fn fold_vis_restricted(&mut self, i: VisRestricted) -> VisRestricted {
         fold_vis_restricted(self, i)
     }
@@ -3165,15 +3161,6 @@ where
     }
 }
 #[cfg(any(feature = "derive", feature = "full"))]
-pub fn fold_vis_public<F>(f: &mut F, node: VisPublic) -> VisPublic
-where
-    F: Fold + ?Sized,
-{
-    VisPublic {
-        pub_token: Token![pub](tokens_helper(f, &node.pub_token.span)),
-    }
-}
-#[cfg(any(feature = "derive", feature = "full"))]
 pub fn fold_vis_restricted<F>(f: &mut F, node: VisRestricted) -> VisRestricted
 where
     F: Fold + ?Sized,
@@ -3192,7 +3179,7 @@ where
 {
     match node {
         Visibility::Public(_binding_0) => {
-            Visibility::Public(f.fold_vis_public(_binding_0))
+            Visibility::Public(Token![pub](tokens_helper(f, &_binding_0.span)))
         }
         Visibility::Restricted(_binding_0) => {
             Visibility::Restricted(f.fold_vis_restricted(_binding_0))
diff --git a/src/gen/hash.rs b/src/gen/hash.rs
index dd74d487..fec790a2 100644
--- a/src/gen/hash.rs
+++ b/src/gen/hash.rs
@@ -2703,14 +2703,6 @@ impl Hash for Variant {
 }
 #[cfg(any(feature = "derive", feature = "full"))]
 #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
-impl Hash for VisPublic {
-    fn hash<H>(&self, _state: &mut H)
-    where
-        H: Hasher,
-    {}
-}
-#[cfg(any(feature = "derive", feature = "full"))]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
 impl Hash for VisRestricted {
     fn hash<H>(&self, state: &mut H)
     where
@@ -2728,9 +2720,8 @@ impl Hash for Visibility {
         H: Hasher,
     {
         match self {
-            Visibility::Public(v0) => {
+            Visibility::Public(_) => {
                 state.write_u8(0u8);
-                v0.hash(state);
             }
             Visibility::Restricted(v0) => {
                 state.write_u8(1u8);
diff --git a/src/gen/visit.rs b/src/gen/visit.rs
index 9047c2ee..1d1f61db 100644
--- a/src/gen/visit.rs
+++ b/src/gen/visit.rs
@@ -725,10 +725,6 @@ pub trait Visit<'ast> {
         visit_variant(self, i);
     }
     #[cfg(any(feature = "derive", feature = "full"))]
-    fn visit_vis_public(&mut self, i: &'ast VisPublic) {
-        visit_vis_public(self, i);
-    }
-    #[cfg(any(feature = "derive", feature = "full"))]
     fn visit_vis_restricted(&mut self, i: &'ast VisRestricted) {
         visit_vis_restricted(self, i);
     }
@@ -3621,13 +3617,6 @@ where
     }
 }
 #[cfg(any(feature = "derive", feature = "full"))]
-pub fn visit_vis_public<'ast, V>(v: &mut V, node: &'ast VisPublic)
-where
-    V: Visit<'ast> + ?Sized,
-{
-    tokens_helper(v, &node.pub_token.span);
-}
-#[cfg(any(feature = "derive", feature = "full"))]
 pub fn visit_vis_restricted<'ast, V>(v: &mut V, node: &'ast VisRestricted)
 where
     V: Visit<'ast> + ?Sized,
@@ -3646,7 +3635,7 @@ where
 {
     match node {
         Visibility::Public(_binding_0) => {
-            v.visit_vis_public(_binding_0);
+            tokens_helper(v, &_binding_0.span);
         }
         Visibility::Restricted(_binding_0) => {
             v.visit_vis_restricted(_binding_0);
diff --git a/src/gen/visit_mut.rs b/src/gen/visit_mut.rs
index 9b6918ad..fcf7663d 100644
--- a/src/gen/visit_mut.rs
+++ b/src/gen/visit_mut.rs
@@ -726,10 +726,6 @@ pub trait VisitMut {
         visit_variant_mut(self, i);
     }
     #[cfg(any(feature = "derive", feature = "full"))]
-    fn visit_vis_public_mut(&mut self, i: &mut VisPublic) {
-        visit_vis_public_mut(self, i);
-    }
-    #[cfg(any(feature = "derive", feature = "full"))]
     fn visit_vis_restricted_mut(&mut self, i: &mut VisRestricted) {
         visit_vis_restricted_mut(self, i);
     }
@@ -3624,13 +3620,6 @@ where
     }
 }
 #[cfg(any(feature = "derive", feature = "full"))]
-pub fn visit_vis_public_mut<V>(v: &mut V, node: &mut VisPublic)
-where
-    V: VisitMut + ?Sized,
-{
-    tokens_helper(v, &mut node.pub_token.span);
-}
-#[cfg(any(feature = "derive", feature = "full"))]
 pub fn visit_vis_restricted_mut<V>(v: &mut V, node: &mut VisRestricted)
 where
     V: VisitMut + ?Sized,
@@ -3649,7 +3638,7 @@ where
 {
     match node {
         Visibility::Public(_binding_0) => {
-            v.visit_vis_public_mut(_binding_0);
+            tokens_helper(v, &mut _binding_0.span);
         }
         Visibility::Restricted(_binding_0) => {
             v.visit_vis_restricted_mut(_binding_0);
diff --git a/src/lib.rs b/src/lib.rs
index 43450a95..d8ede800 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -493,7 +493,7 @@ mod verbatim;
 #[cfg(any(feature = "full", feature = "derive"))]
 mod visibility;
 #[cfg(any(feature = "full", feature = "derive"))]
-pub use crate::visibility::{VisPublic, VisRestricted, Visibility};
+pub use crate::visibility::{VisRestricted, Visibility};
 
 #[cfg(all(feature = "parsing", feature = "full"))]
 mod whitespace;
diff --git a/src/visibility.rs b/src/visibility.rs
index 78fd99fe..2e8f576b 100644
--- a/src/visibility.rs
+++ b/src/visibility.rs
@@ -1,6 +1,6 @@
 use super::*;
 
-ast_enum_of_structs! {
+ast_enum! {
     /// The visibility level of an item: inherited or `pub` or
     /// `pub(restricted)`.
     ///
@@ -12,7 +12,7 @@ ast_enum_of_structs! {
     #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
     pub enum Visibility {
         /// A public visibility level: `pub`.
-        Public(VisPublic),
+        Public(Token![pub]),
 
         /// A visibility level restricted to some path: `pub(self)` or
         /// `pub(super)` or `pub(crate)` or `pub(in some::module)`.
@@ -23,14 +23,6 @@ ast_enum_of_structs! {
     }
 }
 
-ast_struct! {
-    /// A public visibility level: `pub`.
-    #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
-    pub struct VisPublic {
-        pub pub_token: Token![pub],
-    }
-}
-
 ast_struct! {
     /// A visibility level restricted to some path: `pub(self)` or
     /// `pub(super)` or `pub(crate)` or `pub(in some::module)`.
@@ -114,7 +106,7 @@ pub mod parsing {
                 }
             }
 
-            Ok(Visibility::Public(VisPublic { pub_token }))
+            Ok(Visibility::Public(pub_token))
         }
 
         #[cfg(feature = "full")]
@@ -134,9 +126,13 @@ mod printing {
     use quote::ToTokens;
 
     #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
-    impl ToTokens for VisPublic {
+    impl ToTokens for Visibility {
         fn to_tokens(&self, tokens: &mut TokenStream) {
-            self.pub_token.to_tokens(tokens);
+            match self {
+                Visibility::Public(pub_token) => pub_token.to_tokens(tokens),
+                Visibility::Restricted(vis_restricted) => vis_restricted.to_tokens(tokens),
+                Visibility::Inherited => {}
+            }
         }
     }
 
diff --git a/syn.json b/syn.json
index 49401aaa..f229837e 100644
--- a/syn.json
+++ b/syn.json
@@ -5289,20 +5289,6 @@
         }
       }
     },
-    {
-      "ident": "VisPublic",
-      "features": {
-        "any": [
-          "derive",
-          "full"
-        ]
-      },
-      "fields": {
-        "pub_token": {
-          "token": "Pub"
-        }
-      }
-    },
     {
       "ident": "VisRestricted",
       "features": {
@@ -5341,7 +5327,7 @@
       "variants": {
         "Public": [
           {
-            "syn": "VisPublic"
+            "token": "Pub"
           }
         ],
         "Restricted": [


Test patch:
diff --git a/tests/debug/gen.rs b/tests/debug/gen.rs
index 85061afa..54733b18 100644
--- a/tests/debug/gen.rs
+++ b/tests/debug/gen.rs
@@ -5772,13 +5772,6 @@ impl Debug for Lite<syn::Variant> {
         formatter.finish()
     }
 }
-impl Debug for Lite<syn::VisPublic> {
-    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
-        let _val = &self.value;
-        let mut formatter = formatter.debug_struct("VisPublic");
-        formatter.finish()
-    }
-}
 impl Debug for Lite<syn::VisRestricted> {
     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
         let _val = &self.value;
@@ -5804,8 +5797,8 @@ impl Debug for Lite<syn::Visibility> {
         let _val = &self.value;
         match _val {
             syn::Visibility::Public(_val) => {
-                let mut formatter = formatter.debug_struct("Visibility::Public");
-                formatter.finish()
+                formatter.write_str("Visibility::Public")?;
+                Ok(())
             }
             syn::Visibility::Restricted(_val) => {
                 let mut formatter = formatter.debug_struct("Visibility::Restricted");