Skip to content

Commit 944c401

Browse files
committed
don't suggest placing code in block if next token is open-brace
Thanks to the inestimably inimitable Esteban "Estebank" Küber for pointing this out. This is relevant to #46836.
1 parent 4b9b70c commit 944c401

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4486,6 +4486,11 @@ impl<'a> Parser<'a> {
44864486
// Which is valid in other languages, but not Rust.
44874487
match self.parse_stmt_without_recovery(false) {
44884488
Ok(Some(stmt)) => {
4489+
if self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace)) {
4490+
// if the next token is an open brace (e.g., `if a b {`), the place-
4491+
// inside-a-block suggestion would be more likely wrong than right
4492+
return Err(e);
4493+
}
44894494
let mut stmt_span = stmt.span;
44904495
// expand the span to include the semicolon, if it exists
44914496
if self.eat(&token::Semi) {

0 commit comments

Comments
 (0)