about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-05 02:46:13 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-03-10 08:32:34 +0100
commitc303c4463cd3530c634dac8614feac7723ab0c58 (patch)
treedd67f910f7fa6766a578618c874c94079b767231
parent9596dc2a47861d73996a550cba7caf55b2737c17 (diff)
downloadrust-c303c4463cd3530c634dac8614feac7723ab0c58.tar.gz
rust-c303c4463cd3530c634dac8614feac7723ab0c58.zip
use error_block_no_opening_brace more
-rw-r--r--src/librustc_parse/parser/stmt.rs6
-rw-r--r--src/test/ui/parser/block-no-opening-brace.rs30
-rw-r--r--src/test/ui/parser/block-no-opening-brace.stderr53
3 files changed, 88 insertions, 1 deletions
diff --git a/src/librustc_parse/parser/stmt.rs b/src/librustc_parse/parser/stmt.rs
index 3864ec3aaa1..511d4bfccd2 100644
--- a/src/librustc_parse/parser/stmt.rs
+++ b/src/librustc_parse/parser/stmt.rs
@@ -304,7 +304,11 @@ impl<'a> Parser<'a> {
         maybe_whole!(self, NtBlock, |x| (Vec::new(), x));
 
         let lo = self.token.span;
-        self.expect(&token::OpenDelim(token::Brace))?;
+
+        if !self.eat(&token::OpenDelim(token::Brace)) {
+            return self.error_block_no_opening_brace();
+        }
+
         Ok((self.parse_inner_attributes()?, self.parse_block_tail(lo, BlockCheckMode::Default)?))
     }
 
diff --git a/src/test/ui/parser/block-no-opening-brace.rs b/src/test/ui/parser/block-no-opening-brace.rs
new file mode 100644
index 00000000000..169625bf897
--- /dev/null
+++ b/src/test/ui/parser/block-no-opening-brace.rs
@@ -0,0 +1,30 @@
+// edition:2018
+
+#![feature(try_blocks)]
+
+fn main() {}
+
+fn f1() {
+   loop
+     let x = 0; //~ ERROR expected `{`, found keyword `let`
+   }
+
+fn f2() {
+   while true
+     let x = 0; //~ ERROR expected `{`, found keyword `let`
+   }
+
+fn f3() {
+   for x in 0..1
+     let x = 0; //~ ERROR expected `{`, found keyword `let`
+   }
+
+fn f4() {
+   try //~ ERROR expected expression, found reserved keyword `try`
+     let x = 0;
+   }
+
+fn f5() {
+   async //~ ERROR async closures are unstable
+     let x = 0; //~ ERROR expected one of `move`, `|`, or `||`, found keyword `let`
+   }
diff --git a/src/test/ui/parser/block-no-opening-brace.stderr b/src/test/ui/parser/block-no-opening-brace.stderr
new file mode 100644
index 00000000000..56db1147360
--- /dev/null
+++ b/src/test/ui/parser/block-no-opening-brace.stderr
@@ -0,0 +1,53 @@
+error: expected `{`, found keyword `let`
+  --> $DIR/block-no-opening-brace.rs:9:6
+   |
+LL |      let x = 0;
+   |      ^^^-------
+   |      |
+   |      expected `{`
+   |      help: try placing this code inside a block: `{ let x = 0; }`
+
+error: expected `{`, found keyword `let`
+  --> $DIR/block-no-opening-brace.rs:14:6
+   |
+LL |      let x = 0;
+   |      ^^^-------
+   |      |
+   |      expected `{`
+   |      help: try placing this code inside a block: `{ let x = 0; }`
+
+error: expected `{`, found keyword `let`
+  --> $DIR/block-no-opening-brace.rs:19:6
+   |
+LL |      let x = 0;
+   |      ^^^-------
+   |      |
+   |      expected `{`
+   |      help: try placing this code inside a block: `{ let x = 0; }`
+
+error: expected expression, found reserved keyword `try`
+  --> $DIR/block-no-opening-brace.rs:23:4
+   |
+LL |    try
+   |    ^^^ expected expression
+
+error: expected one of `move`, `|`, or `||`, found keyword `let`
+  --> $DIR/block-no-opening-brace.rs:29:6
+   |
+LL |    async
+   |         - expected one of `move`, `|`, or `||`
+LL |      let x = 0;
+   |      ^^^ unexpected token
+
+error[E0658]: async closures are unstable
+  --> $DIR/block-no-opening-brace.rs:28:4
+   |
+LL |    async
+   |    ^^^^^
+   |
+   = note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
+   = help: add `#![feature(async_closure)]` to the crate attributes to enable
+
+error: aborting due to 6 previous errors
+
+For more information about this error, try `rustc --explain E0658`.