@@ -68,18 +68,18 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
68
68
hir:: ExprKind :: Block ( ref b, Some ( _label) ) => {
69
69
self . with_context ( LabeledBlock , |v| v. visit_block ( & b) ) ;
70
70
}
71
- hir:: ExprKind :: Break ( label , ref opt_expr) => {
71
+ hir:: ExprKind :: Break ( break_label , ref opt_expr) => {
72
72
if let Some ( e) = opt_expr {
73
73
self . visit_expr ( e) ;
74
74
}
75
75
76
- if self . require_label_in_labeled_block ( e. span , & label , "break" ) {
76
+ if self . require_label_in_labeled_block ( e. span , & break_label , "break" ) {
77
77
// If we emitted an error about an unlabeled break in a labeled
78
78
// block, we don't need any further checking for this break any more
79
79
return ;
80
80
}
81
81
82
- let loop_id = match label . target_id {
82
+ let loop_id = match break_label . target_id {
83
83
Ok ( loop_id) => Some ( loop_id) ,
84
84
Err ( hir:: LoopIdError :: OutsideLoopScope ) => None ,
85
85
Err ( hir:: LoopIdError :: UnlabeledCfInWhileCondition ) => {
@@ -94,7 +94,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
94
94
}
95
95
96
96
if let Some ( break_expr) = opt_expr {
97
- let ( head, label , loop_kind) = if let Some ( loop_id) = loop_id {
97
+ let ( head, loop_label , loop_kind) = if let Some ( loop_id) = loop_id {
98
98
match self . hir_map . expect_expr ( loop_id) . kind {
99
99
hir:: ExprKind :: Loop ( _, label, source, sp) => {
100
100
( Some ( sp) , label, Some ( source) )
@@ -135,10 +135,15 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
135
135
"use `break` on its own without a value inside this `{}` loop" ,
136
136
kind. name( ) ,
137
137
) ,
138
- "break" . to_string ( ) ,
138
+ format ! (
139
+ "break{}" ,
140
+ break_label
141
+ . label
142
+ . map_or_else( String :: new, |l| format!( " {}" , l. ident) )
143
+ ) ,
139
144
Applicability :: MaybeIncorrect ,
140
145
) ;
141
- if let Some ( label) = label {
146
+ if let ( Some ( label) , None ) = ( loop_label , break_label . label ) {
142
147
match break_expr. kind {
143
148
hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
144
149
None ,
0 commit comments