@@ -669,7 +669,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
669669 last_block_rib : Option < Rib < ' a > > ,
670670
671671 /// The current set of local scopes, for labels.
672- label_ribs : Vec < Rib < ' a , NodeId > > ,
672+ label_ribs : Vec < Rib < ' a , ( NodeId , bool , Span ) > > ,
673673
674674 /// The current set of local scopes for lifetimes.
675675 lifetime_ribs : Vec < LifetimeRib > ,
@@ -2313,7 +2313,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23132313
23142314 /// Searches the current set of local scopes for labels. Returns the `NodeId` of the resolved
23152315 /// label and reports an error if the label is not found or is unreachable.
2316- fn resolve_label ( & mut self , mut label : Ident ) -> Result < ( NodeId , Span ) , ResolutionError < ' a > > {
2316+ fn resolve_label (
2317+ & mut self ,
2318+ mut label : Ident ,
2319+ ) -> Result < ( ( NodeId , bool , Span ) , Span ) , ResolutionError < ' a > > {
23172320 let mut suggestion = None ;
23182321
23192322 for i in ( 0 ..self . label_ribs . len ( ) ) . rev ( ) {
@@ -4330,7 +4333,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43304333 Ok ( Some ( result) )
43314334 }
43324335
4333- fn with_resolved_label ( & mut self , label : Option < Label > , id : NodeId , f : impl FnOnce ( & mut Self ) ) {
4336+ fn with_resolved_label (
4337+ & mut self ,
4338+ label : Option < Label > ,
4339+ id : NodeId ,
4340+ is_loop : bool ,
4341+ span : Span ,
4342+ f : impl FnOnce ( & mut Self ) ,
4343+ ) {
43344344 if let Some ( label) = label {
43354345 if label. ident . as_str ( ) . as_bytes ( ) [ 1 ] != b'_' {
43364346 self . diag_metadata . unused_labels . insert ( id, label. ident . span ) ;
@@ -4342,16 +4352,22 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43424352
43434353 self . with_label_rib ( RibKind :: Normal , |this| {
43444354 let ident = label. ident . normalize_to_macro_rules ( ) ;
4345- this. label_ribs . last_mut ( ) . unwrap ( ) . bindings . insert ( ident, id ) ;
4355+ this. label_ribs . last_mut ( ) . unwrap ( ) . bindings . insert ( ident, ( id , is_loop , span ) ) ;
43464356 f ( this) ;
43474357 } ) ;
43484358 } else {
43494359 f ( self ) ;
43504360 }
43514361 }
43524362
4353- fn resolve_labeled_block ( & mut self , label : Option < Label > , id : NodeId , block : & ' ast Block ) {
4354- self . with_resolved_label ( label, id, |this| this. visit_block ( block) ) ;
4363+ fn resolve_labeled_block (
4364+ & mut self ,
4365+ label : Option < Label > ,
4366+ id : NodeId ,
4367+ block : & ' ast Block ,
4368+ is_loop : bool ,
4369+ ) {
4370+ self . with_resolved_label ( label, id, is_loop, block. span , |this| this. visit_block ( block) ) ;
43554371 }
43564372
43574373 fn resolve_block ( & mut self , block : & ' ast Block ) {
@@ -4494,10 +4510,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
44944510
44954511 ExprKind :: Break ( Some ( label) , _) | ExprKind :: Continue ( Some ( label) ) => {
44964512 match self . resolve_label ( label. ident ) {
4497- Ok ( ( node_id , _) ) => {
4513+ Ok ( ( node , _) ) => {
44984514 // Since this res is a label, it is never read.
4499- self . r . label_res_map . insert ( expr. id , node_id ) ;
4500- self . diag_metadata . unused_labels . remove ( & node_id ) ;
4515+ self . r . label_res_map . insert ( expr. id , node ) ;
4516+ self . diag_metadata . unused_labels . remove ( & node . 0 ) ;
45014517 }
45024518 Err ( error) => {
45034519 self . report_error ( label. ident . span , error) ;
@@ -4532,11 +4548,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
45324548 }
45334549
45344550 ExprKind :: Loop ( ref block, label, _) => {
4535- self . resolve_labeled_block ( label, expr. id , block)
4551+ self . resolve_labeled_block ( label, expr. id , block, true )
45364552 }
45374553
45384554 ExprKind :: While ( ref cond, ref block, label) => {
4539- self . with_resolved_label ( label, expr. id , |this| {
4555+ self . with_resolved_label ( label, expr. id , true , block . span , |this| {
45404556 this. with_rib ( ValueNS , RibKind :: Normal , |this| {
45414557 let old = this. diag_metadata . in_if_condition . replace ( cond) ;
45424558 this. visit_expr ( cond) ;
@@ -4550,11 +4566,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
45504566 self . visit_expr ( iter) ;
45514567 self . with_rib ( ValueNS , RibKind :: Normal , |this| {
45524568 this. resolve_pattern_top ( pat, PatternSource :: For ) ;
4553- this. resolve_labeled_block ( label, expr. id , body) ;
4569+ this. resolve_labeled_block ( label, expr. id , body, true ) ;
45544570 } ) ;
45554571 }
45564572
4557- ExprKind :: Block ( ref block, label) => self . resolve_labeled_block ( label, block. id , block) ,
4573+ ExprKind :: Block ( ref block, label) => {
4574+ self . resolve_labeled_block ( label, block. id , block, false )
4575+ }
45584576
45594577 // Equivalent to `visit::walk_expr` + passing some context to children.
45604578 ExprKind :: Field ( ref subexpression, _) => {
0 commit comments