mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-28 20:16:58 +03:00
parse_labeled_expr: add a suggestion on missing colon.
This commit is contained in:
@@ -1106,14 +1106,24 @@ fn parse_labeled_expr(&mut self, label: Label, attrs: AttrVec) -> PResult<'a, P<
|
||||
}?;
|
||||
|
||||
if !ate_colon {
|
||||
self.struct_span_err(expr.span, "labeled expression must be followed by `:`")
|
||||
.span_label(lo, "the label")
|
||||
.emit();
|
||||
self.error_labeled_expr_must_be_followed_by_colon(lo, expr.span);
|
||||
}
|
||||
|
||||
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.
|
||||
fn recover_do_catch(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
|
||||
let lo = self.token.span;
|
||||
|
||||
Reference in New Issue
Block a user