Repository: dtolnay/syn
Pull request #1325 (2023-01-23 22:37:28)

Add field for generics on Item::Const


Patch:
diff --git a/src/gen/clone.rs b/src/gen/clone.rs
index 627abf7c..2c36e8d5 100644
--- a/src/gen/clone.rs
+++ b/src/gen/clone.rs
@@ -959,6 +959,7 @@ impl Clone for ImplItemConst {
             defaultness: self.defaultness.clone(),
             const_token: self.const_token.clone(),
             ident: self.ident.clone(),
+            generics: self.generics.clone(),
             colon_token: self.colon_token.clone(),
             ty: self.ty.clone(),
             eq_token: self.eq_token.clone(),
@@ -1051,6 +1052,7 @@ impl Clone for ItemConst {
             vis: self.vis.clone(),
             const_token: self.const_token.clone(),
             ident: self.ident.clone(),
+            generics: self.generics.clone(),
             colon_token: self.colon_token.clone(),
             ty: self.ty.clone(),
             eq_token: self.eq_token.clone(),
@@ -1752,6 +1754,7 @@ impl Clone for TraitItemConst {
             attrs: self.attrs.clone(),
             const_token: self.const_token.clone(),
             ident: self.ident.clone(),
+            generics: self.generics.clone(),
             colon_token: self.colon_token.clone(),
             ty: self.ty.clone(),
             default: self.default.clone(),
diff --git a/src/gen/debug.rs b/src/gen/debug.rs
index 6701f551..6e117bbf 100644
--- a/src/gen/debug.rs
+++ b/src/gen/debug.rs
@@ -1361,6 +1361,7 @@ impl Debug for ImplItemConst {
         formatter.field("defaultness", &self.defaultness);
         formatter.field("const_token", &self.const_token);
         formatter.field("ident", &self.ident);
+        formatter.field("generics", &self.generics);
         formatter.field("colon_token", &self.colon_token);
         formatter.field("ty", &self.ty);
         formatter.field("eq_token", &self.eq_token);
@@ -1517,6 +1518,7 @@ impl Debug for ItemConst {
         formatter.field("vis", &self.vis);
         formatter.field("const_token", &self.const_token);
         formatter.field("ident", &self.ident);
+        formatter.field("generics", &self.generics);
         formatter.field("colon_token", &self.colon_token);
         formatter.field("ty", &self.ty);
         formatter.field("eq_token", &self.eq_token);
@@ -2406,6 +2408,7 @@ impl Debug for TraitItemConst {
         formatter.field("attrs", &self.attrs);
         formatter.field("const_token", &self.const_token);
         formatter.field("ident", &self.ident);
+        formatter.field("generics", &self.generics);
         formatter.field("colon_token", &self.colon_token);
         formatter.field("ty", &self.ty);
         formatter.field("default", &self.default);
diff --git a/src/gen/eq.rs b/src/gen/eq.rs
index 8d33c6ce..7d9b05d4 100644
--- a/src/gen/eq.rs
+++ b/src/gen/eq.rs
@@ -947,7 +947,8 @@ impl PartialEq for ImplItemConst {
     fn eq(&self, other: &Self) -> bool {
         self.attrs == other.attrs && self.vis == other.vis
             && self.defaultness == other.defaultness && self.ident == other.ident
-            && self.ty == other.ty && self.expr == other.expr
+            && self.generics == other.generics && self.ty == other.ty
+            && self.expr == other.expr
     }
 }
 #[cfg(feature = "full")]
@@ -1023,7 +1024,8 @@ impl Eq for ItemConst {}
 impl PartialEq for ItemConst {
     fn eq(&self, other: &Self) -> bool {
         self.attrs == other.attrs && self.vis == other.vis && self.ident == other.ident
-            && self.ty == other.ty && self.expr == other.expr
+            && self.generics == other.generics && self.ty == other.ty
+            && self.expr == other.expr
     }
 }
 #[cfg(feature = "full")]
@@ -1691,7 +1693,8 @@ impl Eq for TraitItemConst {}
 #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
 impl PartialEq for TraitItemConst {
     fn eq(&self, other: &Self) -> bool {
-        self.attrs == other.attrs && self.ident == other.ident && self.ty == other.ty
+        self.attrs == other.attrs && self.ident == other.ident
+            && self.generics == other.generics && self.ty == other.ty
             && self.default == other.default
     }
 }
diff --git a/src/gen/fold.rs b/src/gen/fold.rs
index dd53bb45..b29ceac4 100644
--- a/src/gen/fold.rs
+++ b/src/gen/fold.rs
@@ -1828,6 +1828,7 @@ where
             .map(|it| Token![default](tokens_helper(f, &it.span))),
         const_token: Token![const](tokens_helper(f, &node.const_token.span)),
         ident: f.fold_ident(node.ident),
+        generics: f.fold_generics(node.generics),
         colon_token: Token![:](tokens_helper(f, &node.colon_token.spans)),
         ty: f.fold_type(node.ty),
         eq_token: Token![=](tokens_helper(f, &node.eq_token.spans)),
@@ -1928,6 +1929,7 @@ where
         vis: f.fold_visibility(node.vis),
         const_token: Token![const](tokens_helper(f, &node.const_token.span)),
         ident: f.fold_ident(node.ident),
+        generics: f.fold_generics(node.generics),
         colon_token: Token![:](tokens_helper(f, &node.colon_token.spans)),
         ty: Box::new(f.fold_type(*node.ty)),
         eq_token: Token![=](tokens_helper(f, &node.eq_token.spans)),
@@ -2777,6 +2779,7 @@ where
         attrs: FoldHelper::lift(node.attrs, |it| f.fold_attribute(it)),
         const_token: Token![const](tokens_helper(f, &node.const_token.span)),
         ident: f.fold_ident(node.ident),
+        generics: f.fold_generics(node.generics),
         colon_token: Token![:](tokens_helper(f, &node.colon_token.spans)),
         ty: f.fold_type(node.ty),
         default: (node.default)
diff --git a/src/gen/hash.rs b/src/gen/hash.rs
index d70d5c45..de914931 100644
--- a/src/gen/hash.rs
+++ b/src/gen/hash.rs
@@ -1275,6 +1275,7 @@ impl Hash for ImplItemConst {
         self.vis.hash(state);
         self.defaultness.hash(state);
         self.ident.hash(state);
+        self.generics.hash(state);
         self.ty.hash(state);
         self.expr.hash(state);
     }
@@ -1405,6 +1406,7 @@ impl Hash for ItemConst {
         self.attrs.hash(state);
         self.vis.hash(state);
         self.ident.hash(state);
+        self.generics.hash(state);
         self.ty.hash(state);
         self.expr.hash(state);
     }
@@ -2252,6 +2254,7 @@ impl Hash for TraitItemConst {
     {
         self.attrs.hash(state);
         self.ident.hash(state);
+        self.generics.hash(state);
         self.ty.hash(state);
         self.default.hash(state);
     }
diff --git a/src/gen/visit.rs b/src/gen/visit.rs
index 1b3df4ea..bfcc9af0 100644
--- a/src/gen/visit.rs
+++ b/src/gen/visit.rs
@@ -2039,6 +2039,7 @@ where
     }
     tokens_helper(v, &node.const_token.span);
     v.visit_ident(&node.ident);
+    v.visit_generics(&node.generics);
     tokens_helper(v, &node.colon_token.spans);
     v.visit_type(&node.ty);
     tokens_helper(v, &node.eq_token.spans);
@@ -2167,6 +2168,7 @@ where
     v.visit_visibility(&node.vis);
     tokens_helper(v, &node.const_token.span);
     v.visit_ident(&node.ident);
+    v.visit_generics(&node.generics);
     tokens_helper(v, &node.colon_token.spans);
     v.visit_type(&*node.ty);
     tokens_helper(v, &node.eq_token.spans);
@@ -3145,6 +3147,7 @@ where
     }
     tokens_helper(v, &node.const_token.span);
     v.visit_ident(&node.ident);
+    v.visit_generics(&node.generics);
     tokens_helper(v, &node.colon_token.spans);
     v.visit_type(&node.ty);
     if let Some(it) = &node.default {
diff --git a/src/gen/visit_mut.rs b/src/gen/visit_mut.rs
index aeb4d269..a001c286 100644
--- a/src/gen/visit_mut.rs
+++ b/src/gen/visit_mut.rs
@@ -2042,6 +2042,7 @@ where
     }
     tokens_helper(v, &mut node.const_token.span);
     v.visit_ident_mut(&mut node.ident);
+    v.visit_generics_mut(&mut node.generics);
     tokens_helper(v, &mut node.colon_token.spans);
     v.visit_type_mut(&mut node.ty);
     tokens_helper(v, &mut node.eq_token.spans);
@@ -2170,6 +2171,7 @@ where
     v.visit_visibility_mut(&mut node.vis);
     tokens_helper(v, &mut node.const_token.span);
     v.visit_ident_mut(&mut node.ident);
+    v.visit_generics_mut(&mut node.generics);
     tokens_helper(v, &mut node.colon_token.spans);
     v.visit_type_mut(&mut *node.ty);
     tokens_helper(v, &mut node.eq_token.spans);
@@ -3148,6 +3150,7 @@ where
     }
     tokens_helper(v, &mut node.const_token.span);
     v.visit_ident_mut(&mut node.ident);
+    v.visit_generics_mut(&mut node.generics);
     tokens_helper(v, &mut node.colon_token.spans);
     v.visit_type_mut(&mut node.ty);
     if let Some(it) = &mut node.default {
diff --git a/src/item.rs b/src/item.rs
index 6ca27fc5..729e8be8 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -94,6 +94,7 @@ ast_struct! {
         pub vis: Visibility,
         pub const_token: Token![const],
         pub ident: Ident,
+        pub generics: Generics,
         pub colon_token: Token![:],
         pub ty: Box<Type>,
         pub eq_token: Token![=],
@@ -622,6 +623,7 @@ ast_struct! {
         pub attrs: Vec<Attribute>,
         pub const_token: Token![const],
         pub ident: Ident,
+        pub generics: Generics,
         pub colon_token: Token![:],
         pub ty: Type,
         pub default: Option<(Token![=], Expr)>,
@@ -719,6 +721,7 @@ ast_struct! {
         pub defaultness: Option<Token![default]>,
         pub const_token: Token![const],
         pub ident: Ident,
+        pub generics: Generics,
         pub colon_token: Token![:],
         pub ty: Type,
         pub eq_token: Token![=],
@@ -949,6 +952,7 @@ pub mod parsing {
                             vis,
                             const_token,
                             ident,
+                            generics: Generics::default(),
                             colon_token,
                             ty,
                             eq_token: input.parse()?,
@@ -1342,6 +1346,7 @@ pub mod parsing {
                         return Err(lookahead.error());
                     }
                 },
+                generics: Generics::default(),
                 colon_token: input.parse()?,
                 ty: input.parse()?,
                 eq_token: input.parse()?,
@@ -2176,6 +2181,7 @@ pub mod parsing {
                         return Err(lookahead.error());
                     }
                 },
+                generics: Generics::default(),
                 colon_token: input.parse()?,
                 ty: input.parse()?,
                 default: {
@@ -2458,6 +2464,7 @@ pub mod parsing {
                             defaultness,
                             const_token,
                             ident,
+                            generics: Generics::default(),
                             colon_token,
                             ty,
                             eq_token,
@@ -2518,6 +2525,7 @@ pub mod parsing {
                         return Err(lookahead.error());
                     }
                 },
+                generics: Generics::default(),
                 colon_token: input.parse()?,
                 ty: input.parse()?,
                 eq_token: input.parse()?,
diff --git a/syn.json b/syn.json
index 0d462ee1..2e66e617 100644
--- a/syn.json
+++ b/syn.json
@@ -2384,6 +2384,9 @@
         "ident": {
           "proc_macro2": "Ident"
         },
+        "generics": {
+          "syn": "Generics"
+        },
         "colon_token": {
           "token": "Colon"
         },
@@ -2624,6 +2627,9 @@
         "ident": {
           "proc_macro2": "Ident"
         },
+        "generics": {
+          "syn": "Generics"
+        },
         "colon_token": {
           "token": "Colon"
         },
@@ -4405,6 +4411,9 @@
         "ident": {
           "proc_macro2": "Ident"
         },
+        "generics": {
+          "syn": "Generics"
+        },
         "colon_token": {
           "token": "Colon"
         },


Test patch:
diff --git a/tests/debug/gen.rs b/tests/debug/gen.rs
index 46c971e5..2e6286b4 100644
--- a/tests/debug/gen.rs
+++ b/tests/debug/gen.rs
@@ -2423,6 +2423,7 @@ impl Debug for Lite<syn::ImplItem> {
                     formatter.field("defaultness", Print::ref_cast(val));
                 }
                 formatter.field("ident", Lite(&_val.ident));
+                formatter.field("generics", Lite(&_val.generics));
                 formatter.field("ty", Lite(&_val.ty));
                 formatter.field("expr", Lite(&_val.expr));
                 formatter.finish()
@@ -2524,6 +2525,7 @@ impl Debug for Lite<syn::ImplItemConst> {
             formatter.field("defaultness", Print::ref_cast(val));
         }
         formatter.field("ident", Lite(&_val.ident));
+        formatter.field("generics", Lite(&_val.generics));
         formatter.field("ty", Lite(&_val.ty));
         formatter.field("expr", Lite(&_val.expr));
         formatter.finish()
@@ -2622,6 +2624,7 @@ impl Debug for Lite<syn::Item> {
                 }
                 formatter.field("vis", Lite(&_val.vis));
                 formatter.field("ident", Lite(&_val.ident));
+                formatter.field("generics", Lite(&_val.generics));
                 formatter.field("ty", Lite(&_val.ty));
                 formatter.field("expr", Lite(&_val.expr));
                 formatter.finish()
@@ -3009,6 +3012,7 @@ impl Debug for Lite<syn::ItemConst> {
         }
         formatter.field("vis", Lite(&_val.vis));
         formatter.field("ident", Lite(&_val.ident));
+        formatter.field("generics", Lite(&_val.generics));
         formatter.field("ty", Lite(&_val.ty));
         formatter.field("expr", Lite(&_val.expr));
         formatter.finish()
@@ -4627,6 +4631,7 @@ impl Debug for Lite<syn::TraitItem> {
                     formatter.field("attrs", Lite(&_val.attrs));
                 }
                 formatter.field("ident", Lite(&_val.ident));
+                formatter.field("generics", Lite(&_val.generics));
                 formatter.field("ty", Lite(&_val.ty));
                 if let Some(val) = &_val.default {
                     #[derive(RefCast)]
@@ -4761,6 +4766,7 @@ impl Debug for Lite<syn::TraitItemConst> {
             formatter.field("attrs", Lite(&_val.attrs));
         }
         formatter.field("ident", Lite(&_val.ident));
+        formatter.field("generics", Lite(&_val.generics));
         formatter.field("ty", Lite(&_val.ty));
         if let Some(val) = &_val.default {
             #[derive(RefCast)]