about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-08-17 00:13:21 +0800
committerGitHub <noreply@github.com>2018-08-17 00:13:21 +0800
commit1cda84bfdbed2c14ae787cb41ebff1c166ac5fd9 (patch)
treeb7b38447566584642f1f91f7126e2ae8d3da3001 /src
parente6068828bddd8b756512e7f0af6d2126908c891f (diff)
parentb70be5bc7953007c333db510b5784c7a051a9b27 (diff)
downloadrust-1cda84bfdbed2c14ae787cb41ebff1c166ac5fd9.tar.gz
rust-1cda84bfdbed2c14ae787cb41ebff1c166ac5fd9.zip
Rollup merge of #53360 - PramodBisht:issue/51602, r=estebank
Addressed #51602

Fixed #51602
r? @estebank

here I have addressed the case where `in` was not expected right after `if` block. Speaking of `type ascription` I am not sure if this the best approach which I have implemented. Plus I think one more test case can be added to test `type-ascription` case, though I don't have any at this point of time. I will ping you again if all existing testcases pass.
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/parse/parser.rs8
-rw-r--r--src/test/ui/issue-51602.rs15
-rw-r--r--src/test/ui/issue-51602.stderr10
3 files changed, 32 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index b1e1cdee2ee..345464c6664 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -4719,7 +4719,12 @@ impl<'a> Parser<'a> {
         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 @@ 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 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
index 00000000000..a3edecb94f7
--- /dev/null
+++ b/src/test/ui/issue-51602.rs
@@ -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
index 00000000000..ac079b452c5
--- /dev/null
+++ b/src/test/ui/issue-51602.stderr
@@ -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
+