Skip to content

Commit 481598b

Browse files
committed
Auto merge of #84024 - estebank:unclosed-brace-use, r=jackh726
Avoid `;` -> `,` recovery and unclosed `}` recovery from being too verbose Those two recovery attempts have a very bad interaction that causes too unnecessary output. Add a simple gate to avoid interpreting a `;` as a `,` when there are unclosed braces. Fix #83498.
2 parents dbcf345 + 0d71676 commit 481598b

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

compiler/rustc_parse/src/parser/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,8 @@ impl<'a> Parser<'a> {
703703
let mut recovered = false;
704704
let mut trailing = false;
705705
let mut v = vec![];
706+
let unclosed_delims = !self.unclosed_delims.is_empty();
707+
706708
while !self.expect_any_with_type(kets, expect) {
707709
if let token::CloseDelim(..) | token::Eof = self.token.kind {
708710
break;
@@ -723,7 +725,7 @@ impl<'a> Parser<'a> {
723725

724726
// Attempt to keep parsing if it was a similar separator.
725727
if let Some(ref tokens) = t.similar_tokens() {
726-
if tokens.contains(&self.token.kind) {
728+
if tokens.contains(&self.token.kind) && !unclosed_delims {
727729
self.bump();
728730
}
729731
}

src/test/ui/parser/issue-63116.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `;`
1212
LL | impl W <s(f;Y(;]
1313
| ^ expected one of 7 possible tokens
1414

15-
error: expected one of `!`, `&&`, `&`, `(`, `)`, `*`, `+`, `,`, `->`, `...`, `::`, `:`, `<`, `=`, `>`, `?`, `[`, `_`, `async`, `const`, `dyn`, `extern`, `fn`, `for`, `impl`, `unsafe`, lifetime, or path, found `;`
16-
--> $DIR/issue-63116.rs:3:15
15+
error: mismatched closing delimiter: `]`
16+
--> $DIR/issue-63116.rs:3:16
1717
|
1818
LL | impl W <s(f;Y(;]
19-
| -^ help: `)` may belong here
19+
| - ^ mismatched closing delimiter
2020
| |
2121
| unclosed delimiter
2222

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// error-pattern: expected one of `,`, `::`, `as`, or `}`, found `;`
2+
// error-pattern: this file contains an unclosed delimiter
3+
// error-pattern: expected item, found `}`
4+
use foo::{bar, baz;
5+
6+
use std::fmt::Display;
7+
8+
mod bar { }
9+
10+
mod baz { }
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error: this file contains an unclosed delimiter
2+
--> $DIR/use-unclosed-brace.rs:12:14
3+
|
4+
LL | use foo::{bar, baz;
5+
| - unclosed delimiter
6+
...
7+
LL | fn main() {}
8+
| ^
9+
10+
error: expected one of `,`, `::`, `as`, or `}`, found `;`
11+
--> $DIR/use-unclosed-brace.rs:4:19
12+
|
13+
LL | use foo::{bar, baz;
14+
| - ^
15+
| | |
16+
| | expected one of `,`, `::`, `as`, or `}`
17+
| | help: `}` may belong here
18+
| unclosed delimiter
19+
20+
error: expected item, found `}`
21+
--> $DIR/use-unclosed-brace.rs:12:14
22+
|
23+
LL | fn main() {}
24+
| ^ expected item
25+
26+
error: aborting due to 3 previous errors
27+

0 commit comments

Comments
 (0)