Skip to content

Commit

Permalink
Merge pull request #1417 from dtolnay/exprmacro
Browse files Browse the repository at this point in the history
Provide Expr::Macro even with features="full" off
  • Loading branch information
dtolnay authored Mar 22, 2023
2 parents fb1062f + f591c40 commit 4df4c4e
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 32 deletions.
28 changes: 14 additions & 14 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Attribute>,
pub mac: Macro,
}
Expand Down Expand Up @@ -1684,16 +1683,18 @@ 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 {
Err(input.error("unsupported expression; enable syn's features=[\"full\"]"))
}
}

#[cfg(feature = "full")]
fn path_or_macro_or_struct(input: ParseStream, allow_struct: AllowStruct) -> Result<Expr> {
fn path_or_macro_or_struct(
input: ParseStream,
#[cfg(feature = "full")] allow_struct: AllowStruct,
) -> Result<Expr> {
let (qself, path) = path::parsing::qpath(input, true)?;

if qself.is_none()
Expand All @@ -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<Self> {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/gen/clone.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/gen/debug.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/gen/eq.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/gen/fold.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/gen/hash.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/gen/visit.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/gen/visit_mut.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions syn.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4df4c4e

Please sign in to comment.