1
Fork 0

Emit clearer diagnostics for parens around for loop heads

This commit is contained in:
Yuki Okushi 2021-06-18 10:22:23 +09:00
parent 78a46efff0
commit 58765d61ee
No known key found for this signature in database
GPG key ID: DABA5B072961C18A
3 changed files with 7 additions and 7 deletions

View file

@ -1346,8 +1346,9 @@ impl<'a> Parser<'a> {
.span_to_snippet(pat.span.trim_start(begin_par_sp).unwrap())
.unwrap_or_else(|_| pprust::pat_to_string(&pat));
self.struct_span_err(self.prev_token.span, "unexpected closing `)`")
.span_label(begin_par_sp, "opening `(`")
let sp = MultiSpan::from_spans(vec![begin_par_sp, self.prev_token.span]);
self.struct_span_err(sp, "unexpected parenthesis surrounding `for` loop head")
.span_suggestion(
begin_par_sp.to(self.prev_token.span),
"remove parenthesis in `for` loop",

View file

@ -9,7 +9,7 @@ fn main() {
for ( elem in vec ) {
//~^ ERROR expected one of `)`, `,`, `@`, or `|`, found keyword `in`
//~| ERROR unexpected closing `)`
//~| ERROR unexpected parenthesis surrounding `for` loop head
const RECOVERY_WITNESS: () = 0; //~ ERROR mismatched types
}
}

View file

@ -4,13 +4,12 @@ error: expected one of `)`, `,`, `@`, or `|`, found keyword `in`
LL | for ( elem in vec ) {
| ^^ expected one of `)`, `,`, `@`, or `|`
error: unexpected closing `)`
--> $DIR/recover-for-loop-parens-around-head.rs:10:23
error: unexpected parenthesis surrounding `for` loop head
--> $DIR/recover-for-loop-parens-around-head.rs:10:9
|
LL | for ( elem in vec ) {
| --------------^
| ^-------------^
| |
| opening `(`
| help: remove parenthesis in `for` loop: `elem in vec`
error[E0308]: mismatched types