Skip to content

Commit

Permalink
Support parsing Expr::Tuple in derive
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 31, 2024
1 parent 3c24f57 commit a3b5a5c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 47 deletions.
38 changes: 16 additions & 22 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ ast_struct! {
ast_struct! {
/// A tuple expression: `(a, b, c, d)`.
#[cfg_attr(docsrs, doc(cfg(feature = "full")))]
pub struct ExprTuple #full {
pub struct ExprTuple {
pub attrs: Vec<Attribute>,
pub paren_token: token::Paren,
pub elems: Punctuated<Expr, Token![,]>,
Expand Down Expand Up @@ -1111,13 +1111,13 @@ pub(crate) mod parsing {
use crate::expr::{
Arm, ExprArray, ExprAssign, ExprAsync, ExprAwait, ExprBlock, ExprBreak, ExprClosure,
ExprConst, ExprContinue, ExprForLoop, ExprIf, ExprInfer, ExprLet, ExprLoop, ExprMatch,
ExprRange, ExprRepeat, ExprReturn, ExprTry, ExprTryBlock, ExprTuple, ExprUnsafe, ExprWhile,
ExprYield, Label, RangeLimits,
ExprRange, ExprRepeat, ExprReturn, ExprTry, ExprTryBlock, ExprUnsafe, ExprWhile, ExprYield,
Label, RangeLimits,
};
use crate::expr::{
Expr, ExprBinary, ExprCall, ExprCast, ExprField, ExprGroup, ExprIndex, ExprLit, ExprMacro,
ExprMethodCall, ExprParen, ExprPath, ExprReference, ExprStruct, ExprUnary, FieldValue,
Index, Member,
ExprMethodCall, ExprParen, ExprPath, ExprReference, ExprStruct, ExprTuple, ExprUnary,
FieldValue, Index, Member,
};
#[cfg(feature = "full")]
use crate::ext::IdentExt as _;
Expand Down Expand Up @@ -1807,7 +1807,7 @@ pub(crate) mod parsing {
} else if input.peek(Lit) {
input.parse().map(Expr::Lit)
} else if input.peek(token::Paren) {
input.call(expr_paren).map(Expr::Paren)
paren_or_tuple(input)
} else if input.peek(Ident)
|| input.peek(Token![::])
|| input.peek(Token![<])
Expand Down Expand Up @@ -1911,7 +1911,6 @@ pub(crate) mod parsing {
}
}

#[cfg(feature = "full")]
fn paren_or_tuple(input: ParseStream) -> Result<Expr> {
let content;
let paren_token = parenthesized!(content in input);
Expand Down Expand Up @@ -2103,19 +2102,15 @@ pub(crate) mod parsing {
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
impl Parse for ExprParen {
fn parse(input: ParseStream) -> Result<Self> {
expr_paren(input)
let content;
Ok(ExprParen {
attrs: Vec::new(),
paren_token: parenthesized!(content in input),
expr: content.parse()?,
})
}
}

fn expr_paren(input: ParseStream) -> Result<ExprParen> {
let content;
Ok(ExprParen {
attrs: Vec::new(),
paren_token: parenthesized!(content in input),
expr: content.parse()?,
})
}

#[cfg(feature = "full")]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
impl Parse for ExprLet {
Expand Down Expand Up @@ -3000,13 +2995,13 @@ pub(crate) mod printing {
use crate::expr::{
Arm, ExprArray, ExprAssign, ExprAsync, ExprAwait, ExprBlock, ExprBreak, ExprClosure,
ExprConst, ExprContinue, ExprForLoop, ExprIf, ExprInfer, ExprLet, ExprLoop, ExprMatch,
ExprRange, ExprRepeat, ExprReturn, ExprTry, ExprTryBlock, ExprTuple, ExprUnsafe, ExprWhile,
ExprYield, Label, RangeLimits,
ExprRange, ExprRepeat, ExprReturn, ExprTry, ExprTryBlock, ExprUnsafe, ExprWhile, ExprYield,
Label, RangeLimits,
};
use crate::expr::{
Expr, ExprBinary, ExprCall, ExprCast, ExprField, ExprGroup, ExprIndex, ExprLit, ExprMacro,
ExprMethodCall, ExprParen, ExprPath, ExprReference, ExprStruct, ExprUnary, FieldValue,
Index, Member,
ExprMethodCall, ExprParen, ExprPath, ExprReference, ExprStruct, ExprTuple, ExprUnary,
FieldValue, Index, Member,
};
use crate::fixup::FixupContext;
use crate::op::BinOp;
Expand Down Expand Up @@ -3781,7 +3776,6 @@ pub(crate) mod printing {
}
}

#[cfg(feature = "full")]
#[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
impl ToTokens for ExprTuple {
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.

5 changes: 2 additions & 3 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.

10 changes: 5 additions & 5 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.

10 changes: 5 additions & 5 deletions src/gen/visit.rs

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

10 changes: 5 additions & 5 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 a3b5a5c

Please sign in to comment.