Skip to content

Commit 97acbf0

Browse files
authored
Merge pull request #1727 from dtolnay/exprparen
Support parsing Expr::Tuple in derive
2 parents 3c24f57 + a3b5a5c commit 97acbf0

File tree

9 files changed

+38
-47
lines changed

9 files changed

+38
-47
lines changed

src/expr.rs

+16-22
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ ast_struct! {
647647
ast_struct! {
648648
/// A tuple expression: `(a, b, c, d)`.
649649
#[cfg_attr(docsrs, doc(cfg(feature = "full")))]
650-
pub struct ExprTuple #full {
650+
pub struct ExprTuple {
651651
pub attrs: Vec<Attribute>,
652652
pub paren_token: token::Paren,
653653
pub elems: Punctuated<Expr, Token![,]>,
@@ -1111,13 +1111,13 @@ pub(crate) mod parsing {
11111111
use crate::expr::{
11121112
Arm, ExprArray, ExprAssign, ExprAsync, ExprAwait, ExprBlock, ExprBreak, ExprClosure,
11131113
ExprConst, ExprContinue, ExprForLoop, ExprIf, ExprInfer, ExprLet, ExprLoop, ExprMatch,
1114-
ExprRange, ExprRepeat, ExprReturn, ExprTry, ExprTryBlock, ExprTuple, ExprUnsafe, ExprWhile,
1115-
ExprYield, Label, RangeLimits,
1114+
ExprRange, ExprRepeat, ExprReturn, ExprTry, ExprTryBlock, ExprUnsafe, ExprWhile, ExprYield,
1115+
Label, RangeLimits,
11161116
};
11171117
use crate::expr::{
11181118
Expr, ExprBinary, ExprCall, ExprCast, ExprField, ExprGroup, ExprIndex, ExprLit, ExprMacro,
1119-
ExprMethodCall, ExprParen, ExprPath, ExprReference, ExprStruct, ExprUnary, FieldValue,
1120-
Index, Member,
1119+
ExprMethodCall, ExprParen, ExprPath, ExprReference, ExprStruct, ExprTuple, ExprUnary,
1120+
FieldValue, Index, Member,
11211121
};
11221122
#[cfg(feature = "full")]
11231123
use crate::ext::IdentExt as _;
@@ -1807,7 +1807,7 @@ pub(crate) mod parsing {
18071807
} else if input.peek(Lit) {
18081808
input.parse().map(Expr::Lit)
18091809
} else if input.peek(token::Paren) {
1810-
input.call(expr_paren).map(Expr::Paren)
1810+
paren_or_tuple(input)
18111811
} else if input.peek(Ident)
18121812
|| input.peek(Token![::])
18131813
|| input.peek(Token![<])
@@ -1911,7 +1911,6 @@ pub(crate) mod parsing {
19111911
}
19121912
}
19131913

1914-
#[cfg(feature = "full")]
19151914
fn paren_or_tuple(input: ParseStream) -> Result<Expr> {
19161915
let content;
19171916
let paren_token = parenthesized!(content in input);
@@ -2103,19 +2102,15 @@ pub(crate) mod parsing {
21032102
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
21042103
impl Parse for ExprParen {
21052104
fn parse(input: ParseStream) -> Result<Self> {
2106-
expr_paren(input)
2105+
let content;
2106+
Ok(ExprParen {
2107+
attrs: Vec::new(),
2108+
paren_token: parenthesized!(content in input),
2109+
expr: content.parse()?,
2110+
})
21072111
}
21082112
}
21092113

2110-
fn expr_paren(input: ParseStream) -> Result<ExprParen> {
2111-
let content;
2112-
Ok(ExprParen {
2113-
attrs: Vec::new(),
2114-
paren_token: parenthesized!(content in input),
2115-
expr: content.parse()?,
2116-
})
2117-
}
2118-
21192114
#[cfg(feature = "full")]
21202115
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
21212116
impl Parse for ExprLet {
@@ -3000,13 +2995,13 @@ pub(crate) mod printing {
30002995
use crate::expr::{
30012996
Arm, ExprArray, ExprAssign, ExprAsync, ExprAwait, ExprBlock, ExprBreak, ExprClosure,
30022997
ExprConst, ExprContinue, ExprForLoop, ExprIf, ExprInfer, ExprLet, ExprLoop, ExprMatch,
3003-
ExprRange, ExprRepeat, ExprReturn, ExprTry, ExprTryBlock, ExprTuple, ExprUnsafe, ExprWhile,
3004-
ExprYield, Label, RangeLimits,
2998+
ExprRange, ExprRepeat, ExprReturn, ExprTry, ExprTryBlock, ExprUnsafe, ExprWhile, ExprYield,
2999+
Label, RangeLimits,
30053000
};
30063001
use crate::expr::{
30073002
Expr, ExprBinary, ExprCall, ExprCast, ExprField, ExprGroup, ExprIndex, ExprLit, ExprMacro,
3008-
ExprMethodCall, ExprParen, ExprPath, ExprReference, ExprStruct, ExprUnary, FieldValue,
3009-
Index, Member,
3003+
ExprMethodCall, ExprParen, ExprPath, ExprReference, ExprStruct, ExprTuple, ExprUnary,
3004+
FieldValue, Index, Member,
30103005
};
30113006
use crate::fixup::FixupContext;
30123007
use crate::op::BinOp;
@@ -3781,7 +3776,6 @@ pub(crate) mod printing {
37813776
}
37823777
}
37833778

3784-
#[cfg(feature = "full")]
37853779
#[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
37863780
impl ToTokens for ExprTuple {
37873781
fn to_tokens(&self, tokens: &mut TokenStream) {

src/gen/clone.rs

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gen/debug.rs

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gen/eq.rs

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gen/fold.rs

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gen/hash.rs

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gen/visit.rs

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gen/visit_mut.rs

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

syn.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)