@@ -68,18 +68,18 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
6868 hir:: ExprKind :: Block ( ref b, Some ( _label) ) => {
6969 self . with_context ( LabeledBlock , |v| v. visit_block ( & b) ) ;
7070 }
71- hir:: ExprKind :: Break ( label , ref opt_expr) => {
71+ hir:: ExprKind :: Break ( break_label , ref opt_expr) => {
7272 if let Some ( e) = opt_expr {
7373 self . visit_expr ( e) ;
7474 }
7575
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" ) {
7777 // If we emitted an error about an unlabeled break in a labeled
7878 // block, we don't need any further checking for this break any more
7979 return ;
8080 }
8181
82- let loop_id = match label . target_id {
82+ let loop_id = match break_label . target_id {
8383 Ok ( loop_id) => Some ( loop_id) ,
8484 Err ( hir:: LoopIdError :: OutsideLoopScope ) => None ,
8585 Err ( hir:: LoopIdError :: UnlabeledCfInWhileCondition ) => {
@@ -94,7 +94,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
9494 }
9595
9696 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 {
9898 match self . hir_map . expect_expr ( loop_id) . kind {
9999 hir:: ExprKind :: Loop ( _, label, source, sp) => {
100100 ( Some ( sp) , label, Some ( source) )
@@ -135,10 +135,15 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
135135 "use `break` on its own without a value inside this `{}` loop" ,
136136 kind. name( ) ,
137137 ) ,
138- "break" . to_string ( ) ,
138+ format ! (
139+ "break{}" ,
140+ break_label
141+ . label
142+ . map_or_else( String :: new, |l| format!( " {}" , l. ident) )
143+ ) ,
139144 Applicability :: MaybeIncorrect ,
140145 ) ;
141- if let Some ( label) = label {
146+ if let ( Some ( label) , None ) = ( loop_label , break_label . label ) {
142147 match break_expr. kind {
143148 hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
144149 None ,
0 commit comments