Skip to content

Commit

Permalink
Merge pull request #1398 from dtolnay/constclosure
Browse files Browse the repository at this point in the history
Improve parsing of const closure edge cases
  • Loading branch information
dtolnay committed Mar 14, 2023
2 parents e01fcdf + 1f1b2be commit d36cc08
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/expr.rs
Expand Up @@ -1868,7 +1868,7 @@ pub(crate) mod parsing {
Expr::TryBlock(input.parse()?)
} else if input.peek(Token![unsafe]) {
Expr::Unsafe(input.parse()?)
} else if input.peek(Token![const]) {
} else if input.peek(Token![const]) && input.peek2(token::Brace) {
Expr::Const(input.parse()?)
} else if input.peek(token::Brace) {
Expr::Block(input.parse()?)
Expand Down
10 changes: 9 additions & 1 deletion src/stmt.rs
Expand Up @@ -210,7 +210,15 @@ pub(crate) mod parsing {
|| input.peek2(Ident)
&& !(input.peek2(Token![async])
&& (input.peek3(Token![move]) || input.peek3(Token![|]))))
|| input.peek(Token![const]) && !input.peek2(token::Brace)
|| input.peek(Token![const])
&& !(input.peek2(token::Brace)
|| input.peek2(Token![static])
|| input.peek2(Token![async])
&& !(input.peek3(Token![unsafe])
|| input.peek3(Token![extern])
|| input.peek3(Token![fn]))
|| input.peek2(Token![move])
|| input.peek2(Token![|]))
|| input.peek(Token![unsafe]) && !input.peek2(token::Brace)
|| input.peek(Token![async])
&& (input.peek2(Token![unsafe])
Expand Down
3 changes: 0 additions & 3 deletions tests/repo/mod.rs
Expand Up @@ -14,9 +14,6 @@ const REVISION: &str = "22f247c6f3ed388cb702d01c2ff27da658a8b353";

#[rustfmt::skip]
static EXCLUDE_FILES: &[&str] = &[
// TODO: `const move || {}`
"tests/ui/rfc-2632-const-trait-impl/const-closure-parse-not-item.rs",

// Compile-fail expr parameter in const generic position: f::<1 + 2>()
"tests/ui/const-generics/early/closing-args-token.rs",
"tests/ui/const-generics/early/const-expression-parameter.rs",
Expand Down

0 comments on commit d36cc08

Please sign in to comment.