Skip to content

Commit

Permalink
Merge pull request #1020 from dtolnay/rangefull
Browse files Browse the repository at this point in the history
Swap closure body vs ExprRange rhs precedence
  • Loading branch information
dtolnay committed Apr 21, 2021
2 parents 734af30 + d326ab7 commit 5dc4a72
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/expr.rs
Expand Up @@ -1322,6 +1322,7 @@ pub(crate) mod parsing {
let rhs = if input.is_empty()
|| input.peek(Token![,])
|| input.peek(Token![;])
|| input.peek(Token![.]) && !input.peek(Token![..])
|| !allow_struct.0 && input.peek(token::Brace)
{
None
Expand Down Expand Up @@ -1547,7 +1548,13 @@ pub(crate) mod parsing {
paren_token: parenthesized!(content in input),
args: content.parse_terminated(Expr::parse)?,
});
} else if input.peek(Token![.]) && !input.peek(Token![..]) {
} else if input.peek(Token![.])
&& !input.peek(Token![..])
&& match e {
Expr::Range(_) => false,
_ => true,
}
{
let mut dot_token: Token![.] = input.parse()?;

let await_token: Option<token::Await> = input.parse()?;
Expand Down Expand Up @@ -2725,6 +2732,7 @@ pub(crate) mod parsing {
if input.is_empty()
|| input.peek(Token![,])
|| input.peek(Token![;])
|| input.peek(Token![.]) && !input.peek(Token![..])
|| !allow_struct.0 && input.peek(token::Brace)
{
None
Expand Down
18 changes: 18 additions & 0 deletions tests/test_expr.rs
Expand Up @@ -300,3 +300,21 @@ fn test_macro_variable_match_arm() {
}
"###);
}

// https://github.com/dtolnay/syn/issues/1019
#[test]
fn test_closure_vs_rangefull() {
#[rustfmt::skip] // rustfmt bug: https://github.com/rust-lang/rustfmt/issues/4808
let tokens = quote!(|| .. .method());
snapshot!(tokens as Expr, @r###"
Expr::MethodCall {
receiver: Expr::Closure {
output: Default,
body: Expr::Range {
limits: HalfOpen,
},
},
method: "method",
}
"###);
}

0 comments on commit 5dc4a72

Please sign in to comment.