Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c303c44

Browse files
committed
use error_block_no_opening_brace more
1 parent 9596dc2 commit c303c44

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

src/librustc_parse/parser/stmt.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,11 @@ impl<'a> Parser<'a> {
304304
maybe_whole!(self, NtBlock, |x| (Vec::new(), x));
305305

306306
let lo = self.token.span;
307-
self.expect(&token::OpenDelim(token::Brace))?;
307+
308+
if !self.eat(&token::OpenDelim(token::Brace)) {
309+
return self.error_block_no_opening_brace();
310+
}
311+
308312
Ok((self.parse_inner_attributes()?, self.parse_block_tail(lo, BlockCheckMode::Default)?))
309313
}
310314

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// edition:2018
2+
3+
#![feature(try_blocks)]
4+
5+
fn main() {}
6+
7+
fn f1() {
8+
loop
9+
let x = 0; //~ ERROR expected `{`, found keyword `let`
10+
}
11+
12+
fn f2() {
13+
while true
14+
let x = 0; //~ ERROR expected `{`, found keyword `let`
15+
}
16+
17+
fn f3() {
18+
for x in 0..1
19+
let x = 0; //~ ERROR expected `{`, found keyword `let`
20+
}
21+
22+
fn f4() {
23+
try //~ ERROR expected expression, found reserved keyword `try`
24+
let x = 0;
25+
}
26+
27+
fn f5() {
28+
async //~ ERROR async closures are unstable
29+
let x = 0; //~ ERROR expected one of `move`, `|`, or `||`, found keyword `let`
30+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
error: expected `{`, found keyword `let`
2+
--> $DIR/block-no-opening-brace.rs:9:6
3+
|
4+
LL | let x = 0;
5+
| ^^^-------
6+
| |
7+
| expected `{`
8+
| help: try placing this code inside a block: `{ let x = 0; }`
9+
10+
error: expected `{`, found keyword `let`
11+
--> $DIR/block-no-opening-brace.rs:14:6
12+
|
13+
LL | let x = 0;
14+
| ^^^-------
15+
| |
16+
| expected `{`
17+
| help: try placing this code inside a block: `{ let x = 0; }`
18+
19+
error: expected `{`, found keyword `let`
20+
--> $DIR/block-no-opening-brace.rs:19:6
21+
|
22+
LL | let x = 0;
23+
| ^^^-------
24+
| |
25+
| expected `{`
26+
| help: try placing this code inside a block: `{ let x = 0; }`
27+
28+
error: expected expression, found reserved keyword `try`
29+
--> $DIR/block-no-opening-brace.rs:23:4
30+
|
31+
LL | try
32+
| ^^^ expected expression
33+
34+
error: expected one of `move`, `|`, or `||`, found keyword `let`
35+
--> $DIR/block-no-opening-brace.rs:29:6
36+
|
37+
LL | async
38+
| - expected one of `move`, `|`, or `||`
39+
LL | let x = 0;
40+
| ^^^ unexpected token
41+
42+
error[E0658]: async closures are unstable
43+
--> $DIR/block-no-opening-brace.rs:28:4
44+
|
45+
LL | async
46+
| ^^^^^
47+
|
48+
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
49+
= help: add `#![feature(async_closure)]` to the crate attributes to enable
50+
51+
error: aborting due to 6 previous errors
52+
53+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)