]> git.lizzy.rs Git - rust.git/commitdiff
don't suggest placing code in block if next token is open-brace
authorZack M. Davis <code@zackmdavis.net>
Thu, 22 Mar 2018 04:54:06 +0000 (21:54 -0700)
committerZack M. Davis <code@zackmdavis.net>
Mon, 9 Apr 2018 15:45:12 +0000 (08:45 -0700)
Thanks to the inestimably inimitable Esteban "Estebank" Küber for
pointing this out.

This is relevant to #46836.

src/libsyntax/parse/parser.rs

index e6da5bcaa3ae6cc61a8bd84b9445211274fcb2e8..05c6c1352b21a02f553be5be33ba0fa4307ad396 100644 (file)
@@ -4486,6 +4486,11 @@ pub fn parse_block(&mut self) -> PResult<'a, P<Block>> {
             // 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) {