From f591c4012d478adb8e472769e09c5a79a9b67271 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 21 Mar 2023 21:26:29 -0700 Subject: [PATCH] Provide Expr::Macro even with features="full" off --- src/expr.rs | 28 ++++++++++++++-------------- 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, 29 insertions(+), 32 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index ab1fa44c8f..8caccb33fb 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -483,8 +483,7 @@ ast_struct! { ast_struct! { /// A macro invocation expression: `format!("{}", q)`. - #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))] - pub struct ExprMacro #full { + pub struct ExprMacro { pub attrs: Vec, pub mac: Macro, } @@ -1684,7 +1683,7 @@ pub(crate) mod parsing { || input.peek(Token![super]) || input.peek(Token![crate]) { - input.parse().map(Expr::Path) + path_or_macro_or_struct(input) } else if input.is_empty() { Err(input.error("expected an expression")) } else { @@ -1692,8 +1691,10 @@ pub(crate) mod parsing { } } - #[cfg(feature = "full")] - fn path_or_macro_or_struct(input: ParseStream, allow_struct: AllowStruct) -> Result { + fn path_or_macro_or_struct( + input: ParseStream, + #[cfg(feature = "full")] allow_struct: AllowStruct, + ) -> Result { let (qself, path) = path::parsing::qpath(input, true)?; if qself.is_none() @@ -1714,18 +1715,18 @@ pub(crate) mod parsing { })); } + #[cfg(feature = "full")] if allow_struct.0 && input.peek(token::Brace) { - expr_struct_helper(input, qself, path).map(Expr::Struct) - } else { - Ok(Expr::Path(ExprPath { - attrs: Vec::new(), - qself, - path, - })) + return expr_struct_helper(input, qself, path).map(Expr::Struct); } + + Ok(Expr::Path(ExprPath { + attrs: Vec::new(), + qself, + path, + })) } - #[cfg(feature = "full")] #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for ExprMacro { fn parse(input: ParseStream) -> Result { @@ -3054,7 +3055,6 @@ pub(crate) mod printing { } } - #[cfg(feature = "full")] #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] impl ToTokens for ExprMacro { fn to_tokens(&self, tokens: &mut TokenStream) { diff --git a/src/gen/clone.rs b/src/gen/clone.rs index 5d1a37a759..d275f51145 100644 --- a/src/gen/clone.rs +++ b/src/gen/clone.rs @@ -263,7 +263,6 @@ impl Clone for Expr { Expr::Lit(v0) => Expr::Lit(v0.clone()), #[cfg(feature = "full")] Expr::Loop(v0) => Expr::Loop(v0.clone()), - #[cfg(feature = "full")] Expr::Macro(v0) => Expr::Macro(v0.clone()), #[cfg(feature = "full")] Expr::Match(v0) => Expr::Match(v0.clone()), @@ -555,7 +554,7 @@ impl Clone for ExprLoop { } } } -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] #[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))] impl Clone for ExprMacro { fn clone(&self) -> Self { diff --git a/src/gen/debug.rs b/src/gen/debug.rs index 627e5c475a..837fe99f4c 100644 --- a/src/gen/debug.rs +++ b/src/gen/debug.rs @@ -429,7 +429,6 @@ impl Debug for Expr { Expr::Lit(v0) => v0.debug(formatter, "Lit"), #[cfg(feature = "full")] Expr::Loop(v0) => v0.debug(formatter, "Loop"), - #[cfg(feature = "full")] Expr::Macro(v0) => v0.debug(formatter, "Macro"), #[cfg(feature = "full")] Expr::Match(v0) => v0.debug(formatter, "Match"), @@ -830,7 +829,7 @@ impl Debug for ExprLoop { self.debug(formatter, "ExprLoop") } } -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] impl Debug for ExprMacro { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { diff --git a/src/gen/eq.rs b/src/gen/eq.rs index d0a6157450..a7479c300b 100644 --- a/src/gen/eq.rs +++ b/src/gen/eq.rs @@ -282,7 +282,6 @@ impl PartialEq for Expr { (Expr::Lit(self0), Expr::Lit(other0)) => self0 == other0, #[cfg(feature = "full")] (Expr::Loop(self0), Expr::Loop(other0)) => self0 == other0, - #[cfg(feature = "full")] (Expr::Macro(self0), Expr::Macro(other0)) => self0 == other0, #[cfg(feature = "full")] (Expr::Match(self0), Expr::Match(other0)) => self0 == other0, @@ -541,10 +540,10 @@ impl PartialEq for ExprLoop { self.attrs == other.attrs && self.label == other.label && 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 ExprMacro {} -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] impl PartialEq for ExprMacro { fn eq(&self, other: &Self) -> bool { diff --git a/src/gen/fold.rs b/src/gen/fold.rs index 093d2ac942..624c15b174 100644 --- a/src/gen/fold.rs +++ b/src/gen/fold.rs @@ -192,7 +192,7 @@ pub trait Fold { fn fold_expr_loop(&mut self, i: ExprLoop) -> ExprLoop { fold_expr_loop(self, i) } - #[cfg(feature = "full")] + #[cfg(any(feature = "derive", feature = "full"))] fn fold_expr_macro(&mut self, i: ExprMacro) -> ExprMacro { fold_expr_macro(self, i) } @@ -1034,7 +1034,7 @@ where Expr::Let(_binding_0) => Expr::Let(full!(f.fold_expr_let(_binding_0))), Expr::Lit(_binding_0) => Expr::Lit(f.fold_expr_lit(_binding_0)), Expr::Loop(_binding_0) => Expr::Loop(full!(f.fold_expr_loop(_binding_0))), - Expr::Macro(_binding_0) => Expr::Macro(full!(f.fold_expr_macro(_binding_0))), + Expr::Macro(_binding_0) => Expr::Macro(f.fold_expr_macro(_binding_0)), Expr::Match(_binding_0) => Expr::Match(full!(f.fold_expr_match(_binding_0))), Expr::MethodCall(_binding_0) => { Expr::MethodCall(full!(f.fold_expr_method_call(_binding_0))) @@ -1316,7 +1316,7 @@ where body: f.fold_block(node.body), } } -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] pub fn fold_expr_macro(f: &mut F, node: ExprMacro) -> ExprMacro where F: Fold + ?Sized, diff --git a/src/gen/hash.rs b/src/gen/hash.rs index 7da4d031d7..40dfc57f30 100644 --- a/src/gen/hash.rs +++ b/src/gen/hash.rs @@ -431,7 +431,6 @@ impl Hash for Expr { state.write_u8(20u8); v0.hash(state); } - #[cfg(feature = "full")] Expr::Macro(v0) => { state.write_u8(21u8); v0.hash(state); @@ -776,7 +775,7 @@ impl Hash for ExprLoop { 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 ExprMacro { fn hash(&self, state: &mut H) diff --git a/src/gen/visit.rs b/src/gen/visit.rs index bc87e16e29..9eaa24f054 100644 --- a/src/gen/visit.rs +++ b/src/gen/visit.rs @@ -194,7 +194,7 @@ pub trait Visit<'ast> { fn visit_expr_loop(&mut self, i: &'ast ExprLoop) { visit_expr_loop(self, i); } - #[cfg(feature = "full")] + #[cfg(any(feature = "derive", feature = "full"))] fn visit_expr_macro(&mut self, i: &'ast ExprMacro) { visit_expr_macro(self, i); } @@ -1145,7 +1145,7 @@ where full!(v.visit_expr_loop(_binding_0)); } Expr::Macro(_binding_0) => { - full!(v.visit_expr_macro(_binding_0)); + v.visit_expr_macro(_binding_0); } Expr::Match(_binding_0) => { full!(v.visit_expr_match(_binding_0)); @@ -1481,7 +1481,7 @@ where skip!(node.loop_token); v.visit_block(&node.body); } -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] pub fn visit_expr_macro<'ast, V>(v: &mut V, node: &'ast ExprMacro) where V: Visit<'ast> + ?Sized, diff --git a/src/gen/visit_mut.rs b/src/gen/visit_mut.rs index de1fff16f4..83bd1ccf80 100644 --- a/src/gen/visit_mut.rs +++ b/src/gen/visit_mut.rs @@ -195,7 +195,7 @@ pub trait VisitMut { fn visit_expr_loop_mut(&mut self, i: &mut ExprLoop) { visit_expr_loop_mut(self, i); } - #[cfg(feature = "full")] + #[cfg(any(feature = "derive", feature = "full"))] fn visit_expr_macro_mut(&mut self, i: &mut ExprMacro) { visit_expr_macro_mut(self, i); } @@ -1146,7 +1146,7 @@ where full!(v.visit_expr_loop_mut(_binding_0)); } Expr::Macro(_binding_0) => { - full!(v.visit_expr_macro_mut(_binding_0)); + v.visit_expr_macro_mut(_binding_0); } Expr::Match(_binding_0) => { full!(v.visit_expr_match_mut(_binding_0)); @@ -1482,7 +1482,7 @@ where skip!(node.loop_token); v.visit_block_mut(&mut node.body); } -#[cfg(feature = "full")] +#[cfg(any(feature = "derive", feature = "full"))] pub fn visit_expr_macro_mut(v: &mut V, node: &mut ExprMacro) where V: VisitMut + ?Sized, diff --git a/syn.json b/syn.json index 13a649d406..d8109eae82 100644 --- a/syn.json +++ b/syn.json @@ -1450,6 +1450,7 @@ "ident": "ExprMacro", "features": { "any": [ + "derive", "full" ] },