Skip to content

Commit 1994abe

Browse files
committed
Bubble parse error when expecting )
1 parent 075c599 commit 1994abe

File tree

7 files changed

+25
-51
lines changed

7 files changed

+25
-51
lines changed

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,9 @@ impl<'a> Parser<'a> {
875875
if self.token == token::Colon {
876876
// we will try to recover in `maybe_recover_struct_lit_bad_delims`
877877
return Err(expect_err);
878+
} else if let [token::CloseDelim(Delimiter::Parenthesis)] = kets
879+
{
880+
return Err(expect_err);
878881
} else {
879882
expect_err.emit();
880883
break;

tests/ui/lint/issue-103435-extra-parentheses.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
//~^ ERROR unnecessary parentheses around `if` condition
1313

1414
// reported by parser
15-
for _x in 1..10 {}
15+
for(_x in 1..10){}
1616
//~^ ERROR expected one of
1717
//~| ERROR unexpected parentheses surrounding
1818
}

tests/ui/lint/issue-103435-extra-parentheses.stderr

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@ error: expected one of `)`, `,`, `@`, or `|`, found keyword `in`
44
LL | for(_x in 1..10){}
55
| ^^ expected one of `)`, `,`, `@`, or `|`
66

7-
error: unexpected parentheses surrounding `for` loop head
8-
--> $DIR/issue-103435-extra-parentheses.rs:15:8
9-
|
10-
LL | for(_x in 1..10){}
11-
| ^ ^
12-
|
13-
help: remove parentheses in `for` loop
14-
|
15-
LL - for(_x in 1..10){}
16-
LL + for _x in 1..10 {}
17-
|
18-
197
error: unnecessary parentheses around pattern
208
--> $DIR/issue-103435-extra-parentheses.rs:5:11
219
|
@@ -57,5 +45,5 @@ LL - if(2 == 1){}
5745
LL + if 2 == 1 {}
5846
|
5947

60-
error: aborting due to 5 previous errors
48+
error: aborting due to 4 previous errors
6149

tests/ui/parser/issues/issue-68890.stderr

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ error: expected one of `)`, `+`, or `,`, found `a`
88
--> $DIR/issue-68890.rs:1:15
99
|
1010
LL | enum e{A((?'a a+?+l))}
11-
| ^ expected one of `)`, `+`, or `,`
12-
13-
error: expected item, found `)`
14-
--> $DIR/issue-68890.rs:1:21
15-
|
16-
LL | enum e{A((?'a a+?+l))}
17-
| ^ expected item
11+
| - ^ expected one of `)`, `+`, or `,`
12+
| |
13+
| while parsing this enum
1814
|
19-
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
15+
= help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`
2016

21-
error: aborting due to 3 previous errors
17+
error: aborting due to 2 previous errors
2218

tests/ui/parser/recover/recover-enum2.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,20 @@ LL | abc: {},
99
error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `{`
1010
--> $DIR/recover-enum2.rs:25:22
1111
|
12+
LL | enum Test4 {
13+
| ----- while parsing this enum
1214
LL | Nope(i32 {})
1315
| ^ expected one of 7 possible tokens
16+
|
17+
= help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`
18+
19+
error: expected item, found `}`
20+
--> $DIR/recover-enum2.rs:28:1
21+
|
22+
LL | }
23+
| ^ expected item
24+
|
25+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
1426

15-
error: aborting due to 2 previous errors
27+
error: aborting due to 3 previous errors
1628

tests/ui/parser/recover/recover-for-loop-parens-around-head.stderr

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,5 @@ error: expected one of `)`, `,`, `@`, or `|`, found keyword `in`
44
LL | for ( elem in vec ) {
55
| ^^ expected one of `)`, `,`, `@`, or `|`
66

7-
error: unexpected parentheses surrounding `for` loop head
8-
--> $DIR/recover-for-loop-parens-around-head.rs:10:9
9-
|
10-
LL | for ( elem in vec ) {
11-
| ^ ^
12-
|
13-
help: remove parentheses in `for` loop
14-
|
15-
LL - for ( elem in vec ) {
16-
LL + for elem in vec {
17-
|
18-
19-
error[E0308]: mismatched types
20-
--> $DIR/recover-for-loop-parens-around-head.rs:13:38
21-
|
22-
LL | const RECOVERY_WITNESS: () = 0;
23-
| ^ expected `()`, found integer
24-
25-
error: aborting due to 3 previous errors
7+
error: aborting due to previous error
268

27-
For more information about this error, try `rustc --explain E0308`.

tests/ui/parser/recover/recover-parens-around-match-arm-head.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,5 @@ error: expected one of `)`, `,`, `...`, `..=`, `..`, or `|`, found keyword `if`
44
LL | (0 if true) => {
55
| ^^ expected one of `)`, `,`, `...`, `..=`, `..`, or `|`
66

7-
error: expected one of `.`, `=>`, `?`, or an operator, found `)`
8-
--> $DIR/recover-parens-around-match-arm-head.rs:4:19
9-
|
10-
LL | (0 if true) => {
11-
| ^ expected one of `.`, `=>`, `?`, or an operator
12-
13-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
148

0 commit comments

Comments
 (0)