From 516a5b5fbce8bb5679e1e38dcc4480aaba3aa8db Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 20 Mar 2023 04:08:45 -0700 Subject: [PATCH] Provide Expr::Group even with features="full" off --- src/expr.rs | 12 ++++++++---- src/gen/clone.rs | 3 +-- src/gen/debug.rs | 3 +-- src/gen/eq.rs | 5 ++--- src/gen/fold.rs | 6 +++--- src/gen/hash.rs | 3 +-- src/gen/visit.rs | 6 +++--- src/gen/visit_mut.rs | 6 +++--- syn.json | 1 + 9 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 168fceeb2f..d1b3920f50 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -407,7 +407,7 @@ ast_struct! { /// of expressions and is related to `None`-delimited spans in a /// `TokenStream`. #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))] - pub struct ExprGroup #full { + pub struct ExprGroup { pub attrs: Vec, pub group_token: token::Group, pub expr: Box, @@ -1651,7 +1651,13 @@ pub(crate) mod parsing { #[cfg(not(feature = "full"))] fn atom_expr(input: ParseStream, _allow_struct: AllowStruct) -> Result { - if input.peek(Lit) { + if input.peek(token::Group) + && !input.peek2(Token![::]) + && !input.peek2(Token![!]) + && !input.peek2(token::Brace) + { + input.call(expr_group).map(Expr::Group) + } else if input.peek(Lit) { input.parse().map(Expr::Lit) } else if input.peek(token::Paren) { input.call(expr_paren).map(Expr::Paren) @@ -1906,7 +1912,6 @@ pub(crate) mod parsing { } } - #[cfg(feature = "full")] fn expr_group(input: ParseStream) -> Result { let group = crate::group::parse_group(input)?; Ok(ExprGroup { @@ -2958,7 +2963,6 @@ pub(crate) mod printing { } } - #[cfg(feature = "full")] #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] impl ToTokens for ExprGroup { fn to_tokens(&self, tokens: &mut TokenStream) { diff --git a/src/gen/clone.rs b/src/gen/clone.rs index 3e182d7b14..5d1a37a759 100644 --- a/src/gen/clone.rs +++ b/src/gen/clone.rs @@ -252,7 +252,6 @@ impl Clone for Expr { Expr::Field(v0) => Expr::Field(v0.clone()), #[cfg(feature = "full")] Expr::ForLoop(v0) => Expr::ForLoop(v0.clone()), - #[cfg(feature = "full")] Expr::Group(v0) => Expr::Group(v0.clone()), #[cfg(feature = "full")] Expr::If(v0) => Expr::If(v0.clone()), @@ -475,7 +474,7 @@ impl Clone for ExprForLoop { } } } -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] #[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))] impl Clone for ExprGroup { fn clone(&self) -> Self { diff --git a/src/gen/debug.rs b/src/gen/debug.rs index e997a6764f..627e5c475a 100644 --- a/src/gen/debug.rs +++ b/src/gen/debug.rs @@ -418,7 +418,6 @@ impl Debug for Expr { Expr::Field(v0) => v0.debug(formatter, "Field"), #[cfg(feature = "full")] Expr::ForLoop(v0) => v0.debug(formatter, "ForLoop"), - #[cfg(feature = "full")] Expr::Group(v0) => v0.debug(formatter, "Group"), #[cfg(feature = "full")] Expr::If(v0) => v0.debug(formatter, "If"), @@ -715,7 +714,7 @@ impl Debug for ExprForLoop { self.debug(formatter, "ExprForLoop") } } -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] impl Debug for ExprGroup { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { diff --git a/src/gen/eq.rs b/src/gen/eq.rs index dae62fa5e6..d0a6157450 100644 --- a/src/gen/eq.rs +++ b/src/gen/eq.rs @@ -271,7 +271,6 @@ impl PartialEq for Expr { (Expr::Field(self0), Expr::Field(other0)) => self0 == other0, #[cfg(feature = "full")] (Expr::ForLoop(self0), Expr::ForLoop(other0)) => self0 == other0, - #[cfg(feature = "full")] (Expr::Group(self0), Expr::Group(other0)) => self0 == other0, #[cfg(feature = "full")] (Expr::If(self0), Expr::If(other0)) => self0 == other0, @@ -470,10 +469,10 @@ impl PartialEq for ExprForLoop { && self.expr == other.expr && self.body == other.body } } -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] impl Eq for ExprGroup {} -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] impl PartialEq for ExprGroup { fn eq(&self, other: &Self) -> bool { diff --git a/src/gen/fold.rs b/src/gen/fold.rs index 164c341f08..093d2ac942 100644 --- a/src/gen/fold.rs +++ b/src/gen/fold.rs @@ -164,7 +164,7 @@ pub trait Fold { fn fold_expr_for_loop(&mut self, i: ExprForLoop) -> ExprForLoop { fold_expr_for_loop(self, i) } - #[cfg(feature = "full")] + #[cfg(any(feature = "derive", feature = "full"))] fn fold_expr_group(&mut self, i: ExprGroup) -> ExprGroup { fold_expr_group(self, i) } @@ -1027,7 +1027,7 @@ where Expr::ForLoop(_binding_0) => { Expr::ForLoop(full!(f.fold_expr_for_loop(_binding_0))) } - Expr::Group(_binding_0) => Expr::Group(full!(f.fold_expr_group(_binding_0))), + Expr::Group(_binding_0) => Expr::Group(f.fold_expr_group(_binding_0)), Expr::If(_binding_0) => Expr::If(full!(f.fold_expr_if(_binding_0))), Expr::Index(_binding_0) => Expr::Index(f.fold_expr_index(_binding_0)), Expr::Infer(_binding_0) => Expr::Infer(full!(f.fold_expr_infer(_binding_0))), @@ -1234,7 +1234,7 @@ where body: f.fold_block(node.body), } } -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] pub fn fold_expr_group(f: &mut F, node: ExprGroup) -> ExprGroup where F: Fold + ?Sized, diff --git a/src/gen/hash.rs b/src/gen/hash.rs index 6d79eb13b0..7da4d031d7 100644 --- a/src/gen/hash.rs +++ b/src/gen/hash.rs @@ -399,7 +399,6 @@ impl Hash for Expr { state.write_u8(13u8); v0.hash(state); } - #[cfg(feature = "full")] Expr::Group(v0) => { state.write_u8(14u8); v0.hash(state); @@ -696,7 +695,7 @@ impl Hash for ExprForLoop { self.body.hash(state); } } -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] impl Hash for ExprGroup { fn hash(&self, state: &mut H) diff --git a/src/gen/visit.rs b/src/gen/visit.rs index 2f2f05d549..bc87e16e29 100644 --- a/src/gen/visit.rs +++ b/src/gen/visit.rs @@ -166,7 +166,7 @@ pub trait Visit<'ast> { fn visit_expr_for_loop(&mut self, i: &'ast ExprForLoop) { visit_expr_for_loop(self, i); } - #[cfg(feature = "full")] + #[cfg(any(feature = "derive", feature = "full"))] fn visit_expr_group(&mut self, i: &'ast ExprGroup) { visit_expr_group(self, i); } @@ -1124,7 +1124,7 @@ where full!(v.visit_expr_for_loop(_binding_0)); } Expr::Group(_binding_0) => { - full!(v.visit_expr_group(_binding_0)); + v.visit_expr_group(_binding_0); } Expr::If(_binding_0) => { full!(v.visit_expr_if(_binding_0)); @@ -1395,7 +1395,7 @@ where v.visit_expr(&*node.expr); v.visit_block(&node.body); } -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] pub fn visit_expr_group<'ast, V>(v: &mut V, node: &'ast ExprGroup) where V: Visit<'ast> + ?Sized, diff --git a/src/gen/visit_mut.rs b/src/gen/visit_mut.rs index 2841aa9a74..de1fff16f4 100644 --- a/src/gen/visit_mut.rs +++ b/src/gen/visit_mut.rs @@ -167,7 +167,7 @@ pub trait VisitMut { fn visit_expr_for_loop_mut(&mut self, i: &mut ExprForLoop) { visit_expr_for_loop_mut(self, i); } - #[cfg(feature = "full")] + #[cfg(any(feature = "derive", feature = "full"))] fn visit_expr_group_mut(&mut self, i: &mut ExprGroup) { visit_expr_group_mut(self, i); } @@ -1125,7 +1125,7 @@ where full!(v.visit_expr_for_loop_mut(_binding_0)); } Expr::Group(_binding_0) => { - full!(v.visit_expr_group_mut(_binding_0)); + v.visit_expr_group_mut(_binding_0); } Expr::If(_binding_0) => { full!(v.visit_expr_if_mut(_binding_0)); @@ -1396,7 +1396,7 @@ where v.visit_expr_mut(&mut *node.expr); v.visit_block_mut(&mut node.body); } -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] pub fn visit_expr_group_mut(v: &mut V, node: &mut ExprGroup) where V: VisitMut + ?Sized, diff --git a/syn.json b/syn.json index 5dd8ed7c01..3578c03cd2 100644 --- a/syn.json +++ b/syn.json @@ -1263,6 +1263,7 @@ "ident": "ExprGroup", "features": { "any": [ + "derive", "full" ] },