File tree Expand file tree Collapse file tree 2 files changed +31
-14
lines changed
Expand file tree Collapse file tree 2 files changed +31
-14
lines changed Original file line number Diff line number Diff line change @@ -1106,14 +1106,24 @@ impl<'a> Parser<'a> {
11061106 } ?;
11071107
11081108 if !ate_colon {
1109- self . struct_span_err ( expr. span , "labeled expression must be followed by `:`" )
1110- . span_label ( lo, "the label" )
1111- . emit ( ) ;
1109+ self . error_labeled_expr_must_be_followed_by_colon ( lo, expr. span ) ;
11121110 }
11131111
11141112 Ok ( expr)
11151113 }
11161114
1115+ fn error_labeled_expr_must_be_followed_by_colon ( & self , lo : Span , span : Span ) {
1116+ self . struct_span_err ( span, "labeled expression must be followed by `:`" )
1117+ . span_label ( lo, "the label" )
1118+ . span_suggestion_short (
1119+ lo. shrink_to_hi ( ) ,
1120+ "add `:` after the label" ,
1121+ ": " . to_string ( ) ,
1122+ Applicability :: MachineApplicable ,
1123+ )
1124+ . emit ( ) ;
1125+ }
1126+
11171127 /// Recover on the syntax `do catch { ... }` suggesting `try { ... }` instead.
11181128 fn recover_do_catch ( & mut self , attrs : AttrVec ) -> PResult < ' a , P < Expr > > {
11191129 let lo = self . token . span ;
Original file line number Diff line number Diff line change @@ -2,32 +2,36 @@ error: labeled expression must be followed by `:`
22 --> $DIR/labeled-no-colon-expr.rs:4:5
33 |
44LL | 'l0 while false {}
5- | ---^^^^^^^^^^^^^^^
6- | |
5+ | ----^^^^^^^^^^^^^^
6+ | | |
7+ | | help: add `:` after the label
78 | the label
89
910error: labeled expression must be followed by `:`
1011 --> $DIR/labeled-no-colon-expr.rs:5:5
1112 |
1213LL | 'l1 for _ in 0..1 {}
13- | ---^^^^^^^^^^^^^^^^^
14- | |
14+ | ----^^^^^^^^^^^^^^^^
15+ | | |
16+ | | help: add `:` after the label
1517 | the label
1618
1719error: labeled expression must be followed by `:`
1820 --> $DIR/labeled-no-colon-expr.rs:6:5
1921 |
2022LL | 'l2 loop {}
21- | ---^^^^^^^^
22- | |
23+ | ----^^^^^^^
24+ | | |
25+ | | help: add `:` after the label
2326 | the label
2427
2528error: labeled expression must be followed by `:`
2629 --> $DIR/labeled-no-colon-expr.rs:7:5
2730 |
2831LL | 'l3 {}
29- | ---^^^
30- | |
32+ | ----^^
33+ | | |
34+ | | help: add `:` after the label
3135 | the label
3236
3337error: expected `while`, `for`, `loop` or `{` after a label
@@ -40,8 +44,9 @@ error: labeled expression must be followed by `:`
4044 --> $DIR/labeled-no-colon-expr.rs:8:9
4145 |
4246LL | 'l4 0;
43- | --- ^
44- | |
47+ | ----^
48+ | | |
49+ | | help: add `:` after the label
4550 | the label
4651
4752error: cannot use a `block` macro fragment here
@@ -61,7 +66,9 @@ error: labeled expression must be followed by `:`
6166 --> $DIR/labeled-no-colon-expr.rs:16:8
6267 |
6368LL | 'l5 $b;
64- | --- the label
69+ | ---- help: add `:` after the label
70+ | |
71+ | the label
6572...
6673LL | m!({});
6774 | ^^
You can’t perform that action at this time.
0 commit comments