about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2018-03-21 21:54:06 -0700
committerZack M. Davis <code@zackmdavis.net>2018-04-09 08:45:12 -0700
commit944c4017365e0974e7b8c5b52ce2d267e3ab3e4c (patch)
treed30f41f407627035603b140b6dffba95cf596d80
parent4b9b70c394e7f341b4016fce4cbf763d404b26f9 (diff)
downloadrust-944c4017365e0974e7b8c5b52ce2d267e3ab3e4c.tar.gz
rust-944c4017365e0974e7b8c5b52ce2d267e3ab3e4c.zip
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.
-rw-r--r--src/libsyntax/parse/parser.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index e6da5bcaa3a..05c6c1352b2 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -4486,6 +4486,11 @@ impl<'a> Parser<'a> {
             // Which is valid in other languages, but not Rust.
             match self.parse_stmt_without_recovery(false) {
                 Ok(Some(stmt)) => {
+                    if self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace)) {
+                        // if the next token is an open brace (e.g., `if a b {`), the place-
+                        // inside-a-block suggestion would be more likely wrong than right
+                        return Err(e);
+                    }
                     let mut stmt_span = stmt.span;
                     // expand the span to include the semicolon, if it exists
                     if self.eat(&token::Semi) {