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> {
1106
1106
} ?;
1107
1107
1108
1108
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 ) ;
1112
1110
}
1113
1111
1114
1112
Ok ( expr)
1115
1113
}
1116
1114
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
+
1117
1127
/// Recover on the syntax `do catch { ... }` suggesting `try { ... }` instead.
1118
1128
fn recover_do_catch ( & mut self , attrs : AttrVec ) -> PResult < ' a , P < Expr > > {
1119
1129
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 `:`
2
2
--> $DIR/labeled-no-colon-expr.rs:4:5
3
3
|
4
4
LL | 'l0 while false {}
5
- | ---^^^^^^^^^^^^^^^
6
- | |
5
+ | ----^^^^^^^^^^^^^^
6
+ | | |
7
+ | | help: add `:` after the label
7
8
| the label
8
9
9
10
error: labeled expression must be followed by `:`
10
11
--> $DIR/labeled-no-colon-expr.rs:5:5
11
12
|
12
13
LL | 'l1 for _ in 0..1 {}
13
- | ---^^^^^^^^^^^^^^^^^
14
- | |
14
+ | ----^^^^^^^^^^^^^^^^
15
+ | | |
16
+ | | help: add `:` after the label
15
17
| the label
16
18
17
19
error: labeled expression must be followed by `:`
18
20
--> $DIR/labeled-no-colon-expr.rs:6:5
19
21
|
20
22
LL | 'l2 loop {}
21
- | ---^^^^^^^^
22
- | |
23
+ | ----^^^^^^^
24
+ | | |
25
+ | | help: add `:` after the label
23
26
| the label
24
27
25
28
error: labeled expression must be followed by `:`
26
29
--> $DIR/labeled-no-colon-expr.rs:7:5
27
30
|
28
31
LL | 'l3 {}
29
- | ---^^^
30
- | |
32
+ | ----^^
33
+ | | |
34
+ | | help: add `:` after the label
31
35
| the label
32
36
33
37
error: expected `while`, `for`, `loop` or `{` after a label
@@ -40,8 +44,9 @@ error: labeled expression must be followed by `:`
40
44
--> $DIR/labeled-no-colon-expr.rs:8:9
41
45
|
42
46
LL | 'l4 0;
43
- | --- ^
44
- | |
47
+ | ----^
48
+ | | |
49
+ | | help: add `:` after the label
45
50
| the label
46
51
47
52
error: cannot use a `block` macro fragment here
@@ -61,7 +66,9 @@ error: labeled expression must be followed by `:`
61
66
--> $DIR/labeled-no-colon-expr.rs:16:8
62
67
|
63
68
LL | 'l5 $b;
64
- | --- the label
69
+ | ---- help: add `:` after the label
70
+ | |
71
+ | the label
65
72
...
66
73
LL | m!({});
67
74
| ^^
You can’t perform that action at this time.
0 commit comments