use error_block_no_opening_brace more

This commit is contained in:
Mazdak Farrokhzad
2020-03-05 02:46:13 +01:00
parent 9596dc2a47
commit c303c4463c
3 changed files with 88 additions and 1 deletions
+5 -1
View File
@@ -304,7 +304,11 @@ pub(super) fn parse_inner_attrs_and_block(
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)?))
}
@@ -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`
}
@@ -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`.