parse_labeled_expr: add a suggestion on missing colon.
This commit is contained in:
parent
fe848b44fe
commit
e72df7edad
2 changed files with 31 additions and 14 deletions
|
@ -1106,14 +1106,24 @@ impl<'a> Parser<'a> {
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
if !ate_colon {
|
if !ate_colon {
|
||||||
self.struct_span_err(expr.span, "labeled expression must be followed by `:`")
|
self.error_labeled_expr_must_be_followed_by_colon(lo, expr.span);
|
||||||
.span_label(lo, "the label")
|
|
||||||
.emit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(expr)
|
Ok(expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn error_labeled_expr_must_be_followed_by_colon(&self, lo: Span, span: Span) {
|
||||||
|
self.struct_span_err(span, "labeled expression must be followed by `:`")
|
||||||
|
.span_label(lo, "the label")
|
||||||
|
.span_suggestion_short(
|
||||||
|
lo.shrink_to_hi(),
|
||||||
|
"add `:` after the label",
|
||||||
|
": ".to_string(),
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
)
|
||||||
|
.emit();
|
||||||
|
}
|
||||||
|
|
||||||
/// Recover on the syntax `do catch { ... }` suggesting `try { ... }` instead.
|
/// Recover on the syntax `do catch { ... }` suggesting `try { ... }` instead.
|
||||||
fn recover_do_catch(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
|
fn recover_do_catch(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
|
||||||
let lo = self.token.span;
|
let lo = self.token.span;
|
||||||
|
|
|
@ -2,32 +2,36 @@ error: labeled expression must be followed by `:`
|
||||||
--> $DIR/labeled-no-colon-expr.rs:4:5
|
--> $DIR/labeled-no-colon-expr.rs:4:5
|
||||||
|
|
|
|
||||||
LL | 'l0 while false {}
|
LL | 'l0 while false {}
|
||||||
| ---^^^^^^^^^^^^^^^
|
| ----^^^^^^^^^^^^^^
|
||||||
| |
|
| | |
|
||||||
|
| | help: add `:` after the label
|
||||||
| the label
|
| the label
|
||||||
|
|
||||||
error: labeled expression must be followed by `:`
|
error: labeled expression must be followed by `:`
|
||||||
--> $DIR/labeled-no-colon-expr.rs:5:5
|
--> $DIR/labeled-no-colon-expr.rs:5:5
|
||||||
|
|
|
|
||||||
LL | 'l1 for _ in 0..1 {}
|
LL | 'l1 for _ in 0..1 {}
|
||||||
| ---^^^^^^^^^^^^^^^^^
|
| ----^^^^^^^^^^^^^^^^
|
||||||
| |
|
| | |
|
||||||
|
| | help: add `:` after the label
|
||||||
| the label
|
| the label
|
||||||
|
|
||||||
error: labeled expression must be followed by `:`
|
error: labeled expression must be followed by `:`
|
||||||
--> $DIR/labeled-no-colon-expr.rs:6:5
|
--> $DIR/labeled-no-colon-expr.rs:6:5
|
||||||
|
|
|
|
||||||
LL | 'l2 loop {}
|
LL | 'l2 loop {}
|
||||||
| ---^^^^^^^^
|
| ----^^^^^^^
|
||||||
| |
|
| | |
|
||||||
|
| | help: add `:` after the label
|
||||||
| the label
|
| the label
|
||||||
|
|
||||||
error: labeled expression must be followed by `:`
|
error: labeled expression must be followed by `:`
|
||||||
--> $DIR/labeled-no-colon-expr.rs:7:5
|
--> $DIR/labeled-no-colon-expr.rs:7:5
|
||||||
|
|
|
|
||||||
LL | 'l3 {}
|
LL | 'l3 {}
|
||||||
| ---^^^
|
| ----^^
|
||||||
| |
|
| | |
|
||||||
|
| | help: add `:` after the label
|
||||||
| the label
|
| the label
|
||||||
|
|
||||||
error: expected `while`, `for`, `loop` or `{` after a label
|
error: expected `while`, `for`, `loop` or `{` after a label
|
||||||
|
@ -40,8 +44,9 @@ error: labeled expression must be followed by `:`
|
||||||
--> $DIR/labeled-no-colon-expr.rs:8:9
|
--> $DIR/labeled-no-colon-expr.rs:8:9
|
||||||
|
|
|
|
||||||
LL | 'l4 0;
|
LL | 'l4 0;
|
||||||
| --- ^
|
| ----^
|
||||||
| |
|
| | |
|
||||||
|
| | help: add `:` after the label
|
||||||
| the label
|
| the label
|
||||||
|
|
||||||
error: cannot use a `block` macro fragment here
|
error: cannot use a `block` macro fragment here
|
||||||
|
@ -61,7 +66,9 @@ error: labeled expression must be followed by `:`
|
||||||
--> $DIR/labeled-no-colon-expr.rs:16:8
|
--> $DIR/labeled-no-colon-expr.rs:16:8
|
||||||
|
|
|
|
||||||
LL | 'l5 $b;
|
LL | 'l5 $b;
|
||||||
| --- the label
|
| ---- help: add `:` after the label
|
||||||
|
| |
|
||||||
|
| the label
|
||||||
...
|
...
|
||||||
LL | m!({});
|
LL | m!({});
|
||||||
| ^^
|
| ^^
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue