]> git.lizzy.rs Git - rust.git/commitdiff
Adddressed #51602
authorPramod Bisht <pramodpsb@outlook.com>
Tue, 14 Aug 2018 19:05:27 +0000 (19:05 +0000)
committerPramod Bisht <pramodpsb@outlook.com>
Tue, 14 Aug 2018 19:05:27 +0000 (19:05 +0000)
src/libsyntax/parse/parser.rs
src/test/ui/issue-51602.rs [new file with mode: 0644]
src/test/ui/issue-51602.stderr [new file with mode: 0644]

index 0e45cacaf38c91727ae3227bb5763898eed3ec13..8e11104b3f68ebe39fefe2018ff2f484c3f94e58 100644 (file)
@@ -4719,7 +4719,12 @@ pub fn parse_block(&mut self) -> PResult<'a, P<Block>> {
         if !self.eat(&token::OpenDelim(token::Brace)) {
             let sp = self.span;
             let tok = self.this_token_to_string();
+            let mut do_not_suggest_help = false;
             let mut e = self.span_fatal(sp, &format!("expected `{{`, found `{}`", tok));
+            if self.token.is_keyword(keywords::In) || self.token == token::Colon {
+                do_not_suggest_help = true;
+                e.span_label(sp, "expected `{`");
+            }
 
             // Check to see if the user has written something like
             //
@@ -4729,7 +4734,8 @@ 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 self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace))
+                        || do_not_suggest_help {
                         // 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);
diff --git a/src/test/ui/issue-51602.rs b/src/test/ui/issue-51602.rs
new file mode 100644 (file)
index 0000000..a3edecb
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main(){
+    if i in 1..10 {
+        break;
+    }
+}
diff --git a/src/test/ui/issue-51602.stderr b/src/test/ui/issue-51602.stderr
new file mode 100644 (file)
index 0000000..ac079b4
--- /dev/null
@@ -0,0 +1,10 @@
+error: expected `{`, found `in`
+  --> $DIR/issue-51602.rs:12:10
+   |
+LL |     if i in 1..10 {
+   |     --   ^^ expected `{`
+   |     |
+   |     this `if` statement has a condition, but no block
+
+error: aborting due to previous error
+