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.
This commit is contained in:
commit
481598b26d
4 changed files with 45 additions and 4 deletions
|
@ -703,6 +703,8 @@ impl<'a> Parser<'a> {
|
||||||
let mut recovered = false;
|
let mut recovered = false;
|
||||||
let mut trailing = false;
|
let mut trailing = false;
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
|
let unclosed_delims = !self.unclosed_delims.is_empty();
|
||||||
|
|
||||||
while !self.expect_any_with_type(kets, expect) {
|
while !self.expect_any_with_type(kets, expect) {
|
||||||
if let token::CloseDelim(..) | token::Eof = self.token.kind {
|
if let token::CloseDelim(..) | token::Eof = self.token.kind {
|
||||||
break;
|
break;
|
||||||
|
@ -723,7 +725,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
// Attempt to keep parsing if it was a similar separator.
|
// Attempt to keep parsing if it was a similar separator.
|
||||||
if let Some(ref tokens) = t.similar_tokens() {
|
if let Some(ref tokens) = t.similar_tokens() {
|
||||||
if tokens.contains(&self.token.kind) {
|
if tokens.contains(&self.token.kind) && !unclosed_delims {
|
||||||
self.bump();
|
self.bump();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,11 @@ error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `;`
|
||||||
LL | impl W <s(f;Y(;]
|
LL | impl W <s(f;Y(;]
|
||||||
| ^ expected one of 7 possible tokens
|
| ^ expected one of 7 possible tokens
|
||||||
|
|
||||||
error: expected one of `!`, `&&`, `&`, `(`, `)`, `*`, `+`, `,`, `->`, `...`, `::`, `:`, `<`, `=`, `>`, `?`, `[`, `_`, `async`, `const`, `dyn`, `extern`, `fn`, `for`, `impl`, `unsafe`, lifetime, or path, found `;`
|
error: mismatched closing delimiter: `]`
|
||||||
--> $DIR/issue-63116.rs:3:15
|
--> $DIR/issue-63116.rs:3:16
|
||||||
|
|
|
|
||||||
LL | impl W <s(f;Y(;]
|
LL | impl W <s(f;Y(;]
|
||||||
| -^ help: `)` may belong here
|
| - ^ mismatched closing delimiter
|
||||||
| |
|
| |
|
||||||
| unclosed delimiter
|
| unclosed delimiter
|
||||||
|
|
||||||
|
|
12
src/test/ui/parser/use-unclosed-brace.rs
Normal file
12
src/test/ui/parser/use-unclosed-brace.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// error-pattern: expected one of `,`, `::`, `as`, or `}`, found `;`
|
||||||
|
// error-pattern: this file contains an unclosed delimiter
|
||||||
|
// error-pattern: expected item, found `}`
|
||||||
|
use foo::{bar, baz;
|
||||||
|
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
mod bar { }
|
||||||
|
|
||||||
|
mod baz { }
|
||||||
|
|
||||||
|
fn main() {}
|
27
src/test/ui/parser/use-unclosed-brace.stderr
Normal file
27
src/test/ui/parser/use-unclosed-brace.stderr
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
error: this file contains an unclosed delimiter
|
||||||
|
--> $DIR/use-unclosed-brace.rs:12:14
|
||||||
|
|
|
||||||
|
LL | use foo::{bar, baz;
|
||||||
|
| - unclosed delimiter
|
||||||
|
...
|
||||||
|
LL | fn main() {}
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: expected one of `,`, `::`, `as`, or `}`, found `;`
|
||||||
|
--> $DIR/use-unclosed-brace.rs:4:19
|
||||||
|
|
|
||||||
|
LL | use foo::{bar, baz;
|
||||||
|
| - ^
|
||||||
|
| | |
|
||||||
|
| | expected one of `,`, `::`, `as`, or `}`
|
||||||
|
| | help: `}` may belong here
|
||||||
|
| unclosed delimiter
|
||||||
|
|
||||||
|
error: expected item, found `}`
|
||||||
|
--> $DIR/use-unclosed-brace.rs:12:14
|
||||||
|
|
|
||||||
|
LL | fn main() {}
|
||||||
|
| ^ expected item
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue