add recovery to parse_labeled_expr
This commit is contained in:
parent
3ed5ba7fa8
commit
4e01b70964
@ -1096,9 +1096,11 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
let msg = "expected `while`, `for`, `loop` or `{` after a label";
|
||||
let mut err = self.fatal(msg);
|
||||
err.span_label(self.token.span, msg);
|
||||
return Err(err);
|
||||
self.struct_span_err(self.token.span, msg)
|
||||
.span_label(self.token.span, msg)
|
||||
.emit();
|
||||
// Continue as an expression in an effort to recover on `'label: non_block_expr`.
|
||||
self.parse_expr()
|
||||
}
|
||||
|
||||
/// Returns a string literal if the next token is a string literal.
|
||||
|
5
src/test/ui/parser/recover-labeled-non-block-expr.rs
Normal file
5
src/test/ui/parser/recover-labeled-non-block-expr.rs
Normal file
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
'label: 1 + 1; //~ ERROR expected `while`, `for`, `loop` or `{` after a label
|
||||
|
||||
let _recovery_witness: () = 0; //~ ERROR mismatched types
|
||||
}
|
17
src/test/ui/parser/recover-labeled-non-block-expr.stderr
Normal file
17
src/test/ui/parser/recover-labeled-non-block-expr.stderr
Normal file
@ -0,0 +1,17 @@
|
||||
error: expected `while`, `for`, `loop` or `{` after a label
|
||||
--> $DIR/recover-labeled-non-block-expr.rs:2:13
|
||||
|
|
||||
LL | 'label: 1 + 1;
|
||||
| ^ expected `while`, `for`, `loop` or `{` after a label
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/recover-labeled-non-block-expr.rs:4:33
|
||||
|
|
||||
LL | let _recovery_witness: () = 0;
|
||||
| -- ^ expected `()`, found integer
|
||||
| |
|
||||
| expected due to this
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Reference in New Issue
Block a user