about summary refs log tree commit diff
path: root/src/librustc_parse
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-06 03:43:59 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-03-10 08:35:23 +0100
commite72df7edadcc2ff3fba93b1a0a2e321dc45f8d65 (patch)
tree9aa69df086f2ee9618e7044a0156298fa5f8868e /src/librustc_parse
parentfe848b44feb5078f4f5c81bca0b61a29f71b6ef2 (diff)
downloadrust-e72df7edadcc2ff3fba93b1a0a2e321dc45f8d65.tar.gz
rust-e72df7edadcc2ff3fba93b1a0a2e321dc45f8d65.zip
parse_labeled_expr: add a suggestion on missing colon.
Diffstat (limited to 'src/librustc_parse')
-rw-r--r--src/librustc_parse/parser/expr.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs
index 5b39701001f..bab6a58296d 100644
--- a/src/librustc_parse/parser/expr.rs
+++ b/src/librustc_parse/parser/expr.rs
@@ -1106,14 +1106,24 @@ impl<'a> Parser<'a> {
         }?;
 
         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;