@@ -658,7 +658,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
658658     last_block_rib :  Option < Rib < ' a > > , 
659659
660660    /// The current set of local scopes, for labels. 
661-      label_ribs :  Vec < Rib < ' a ,  NodeId > > , 
661+      label_ribs :  Vec < Rib < ' a ,  ( NodeId ,   bool ,   Span ) > > , 
662662
663663    /// The current set of local scopes for lifetimes. 
664664     lifetime_ribs :  Vec < LifetimeRib > , 
@@ -2215,7 +2215,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
22152215
22162216    /// Searches the current set of local scopes for labels. Returns the `NodeId` of the resolved 
22172217     /// label and reports an error if the label is not found or is unreachable. 
2218-      fn  resolve_label ( & mut  self ,  mut  label :  Ident )  -> Result < ( NodeId ,  Span ) ,  ResolutionError < ' a > >  { 
2218+      fn  resolve_label ( 
2219+         & mut  self , 
2220+         mut  label :  Ident , 
2221+     )  -> Result < ( ( NodeId ,  bool ,  Span ) ,  Span ) ,  ResolutionError < ' a > >  { 
22192222        let  mut  suggestion = None ; 
22202223
22212224        for  i in  ( 0 ..self . label_ribs . len ( ) ) . rev ( )  { 
@@ -4184,7 +4187,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
41844187        Ok ( Some ( result) ) 
41854188    } 
41864189
4187-     fn  with_resolved_label ( & mut  self ,  label :  Option < Label > ,  id :  NodeId ,  f :  impl  FnOnce ( & mut  Self ) )  { 
4190+     fn  with_resolved_label ( 
4191+         & mut  self , 
4192+         label :  Option < Label > , 
4193+         id :  NodeId , 
4194+         is_loop :  bool , 
4195+         span :  Span , 
4196+         f :  impl  FnOnce ( & mut  Self ) , 
4197+     )  { 
41884198        if  let  Some ( label)  = label { 
41894199            if  label. ident . as_str ( ) . as_bytes ( ) [ 1 ]  != b'_'  { 
41904200                self . diagnostic_metadata . unused_labels . insert ( id,  label. ident . span ) ; 
@@ -4196,16 +4206,22 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
41964206
41974207            self . with_label_rib ( RibKind :: Normal ,  |this| { 
41984208                let  ident = label. ident . normalize_to_macro_rules ( ) ; 
4199-                 this. label_ribs . last_mut ( ) . unwrap ( ) . bindings . insert ( ident,  id ) ; 
4209+                 this. label_ribs . last_mut ( ) . unwrap ( ) . bindings . insert ( ident,  ( id ,  is_loop ,  span ) ) ; 
42004210                f ( this) ; 
42014211            } ) ; 
42024212        }  else  { 
42034213            f ( self ) ; 
42044214        } 
42054215    } 
42064216
4207-     fn  resolve_labeled_block ( & mut  self ,  label :  Option < Label > ,  id :  NodeId ,  block :  & ' ast  Block )  { 
4208-         self . with_resolved_label ( label,  id,  |this| this. visit_block ( block) ) ; 
4217+     fn  resolve_labeled_block ( 
4218+         & mut  self , 
4219+         label :  Option < Label > , 
4220+         id :  NodeId , 
4221+         block :  & ' ast  Block , 
4222+         is_loop :  bool , 
4223+     )  { 
4224+         self . with_resolved_label ( label,  id,  is_loop,  block. span ,  |this| this. visit_block ( block) ) ; 
42094225    } 
42104226
42114227    fn  resolve_block ( & mut  self ,  block :  & ' ast  Block )  { 
@@ -4348,10 +4364,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43484364
43494365            ExprKind :: Break ( Some ( label) ,  _)  | ExprKind :: Continue ( Some ( label) )  => { 
43504366                match  self . resolve_label ( label. ident )  { 
4351-                     Ok ( ( node_id ,  _) )  => { 
4367+                     Ok ( ( node ,  _) )  => { 
43524368                        // Since this res is a label, it is never read. 
4353-                         self . r . label_res_map . insert ( expr. id ,  node_id ) ; 
4354-                         self . diagnostic_metadata . unused_labels . remove ( & node_id ) ; 
4369+                         self . r . label_res_map . insert ( expr. id ,  node ) ; 
4370+                         self . diagnostic_metadata . unused_labels . remove ( & node . 0 ) ; 
43554371                    } 
43564372                    Err ( error)  => { 
43574373                        self . report_error ( label. ident . span ,  error) ; 
@@ -4386,11 +4402,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43864402            } 
43874403
43884404            ExprKind :: Loop ( ref  block,  label,  _)  => { 
4389-                 self . resolve_labeled_block ( label,  expr. id ,  block) 
4405+                 self . resolve_labeled_block ( label,  expr. id ,  block,   true ) 
43904406            } 
43914407
43924408            ExprKind :: While ( ref  cond,  ref  block,  label)  => { 
4393-                 self . with_resolved_label ( label,  expr. id ,  |this| { 
4409+                 self . with_resolved_label ( label,  expr. id ,  true ,  block . span ,   |this| { 
43944410                    this. with_rib ( ValueNS ,  RibKind :: Normal ,  |this| { 
43954411                        let  old = this. diagnostic_metadata . in_if_condition . replace ( cond) ; 
43964412                        this. visit_expr ( cond) ; 
@@ -4404,11 +4420,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
44044420                self . visit_expr ( iter) ; 
44054421                self . with_rib ( ValueNS ,  RibKind :: Normal ,  |this| { 
44064422                    this. resolve_pattern_top ( pat,  PatternSource :: For ) ; 
4407-                     this. resolve_labeled_block ( label,  expr. id ,  body) ; 
4423+                     this. resolve_labeled_block ( label,  expr. id ,  body,   true ) ; 
44084424                } ) ; 
44094425            } 
44104426
4411-             ExprKind :: Block ( ref  block,  label)  => self . resolve_labeled_block ( label,  block. id ,  block) , 
4427+             ExprKind :: Block ( ref  block,  label)  => { 
4428+                 self . resolve_labeled_block ( label,  block. id ,  block,  false ) 
4429+             } 
44124430
44134431            // Equivalent to `visit::walk_expr` + passing some context to children. 
44144432            ExprKind :: Field ( ref  subexpression,  _)  => { 
0 commit comments