@@ -672,7 +672,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
672672 last_block_rib : Option < Rib < ' a > > ,
673673
674674 /// The current set of local scopes, for labels.
675- label_ribs : Vec < Rib < ' a , NodeId > > ,
675+ label_ribs : Vec < Rib < ' a , ( NodeId , bool , Span ) > > ,
676676
677677 /// The current set of local scopes for lifetimes.
678678 lifetime_ribs : Vec < LifetimeRib > ,
@@ -2316,7 +2316,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23162316
23172317 /// Searches the current set of local scopes for labels. Returns the `NodeId` of the resolved
23182318 /// label and reports an error if the label is not found or is unreachable.
2319- fn resolve_label ( & mut self , mut label : Ident ) -> Result < ( NodeId , Span ) , ResolutionError < ' a > > {
2319+ fn resolve_label (
2320+ & mut self ,
2321+ mut label : Ident ,
2322+ ) -> Result < ( ( NodeId , bool , Span ) , Span ) , ResolutionError < ' a > > {
23202323 let mut suggestion = None ;
23212324
23222325 for i in ( 0 ..self . label_ribs . len ( ) ) . rev ( ) {
@@ -4333,7 +4336,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43334336 Ok ( Some ( result) )
43344337 }
43354338
4336- fn with_resolved_label ( & mut self , label : Option < Label > , id : NodeId , f : impl FnOnce ( & mut Self ) ) {
4339+ fn with_resolved_label (
4340+ & mut self ,
4341+ label : Option < Label > ,
4342+ id : NodeId ,
4343+ is_loop : bool ,
4344+ span : Span ,
4345+ f : impl FnOnce ( & mut Self ) ,
4346+ ) {
43374347 if let Some ( label) = label {
43384348 if label. ident . as_str ( ) . as_bytes ( ) [ 1 ] != b'_' {
43394349 self . diag_metadata . unused_labels . insert ( id, label. ident . span ) ;
@@ -4345,16 +4355,22 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43454355
43464356 self . with_label_rib ( RibKind :: Normal , |this| {
43474357 let ident = label. ident . normalize_to_macro_rules ( ) ;
4348- this. label_ribs . last_mut ( ) . unwrap ( ) . bindings . insert ( ident, id ) ;
4358+ this. label_ribs . last_mut ( ) . unwrap ( ) . bindings . insert ( ident, ( id , is_loop , span ) ) ;
43494359 f ( this) ;
43504360 } ) ;
43514361 } else {
43524362 f ( self ) ;
43534363 }
43544364 }
43554365
4356- fn resolve_labeled_block ( & mut self , label : Option < Label > , id : NodeId , block : & ' ast Block ) {
4357- self . with_resolved_label ( label, id, |this| this. visit_block ( block) ) ;
4366+ fn resolve_labeled_block (
4367+ & mut self ,
4368+ label : Option < Label > ,
4369+ id : NodeId ,
4370+ block : & ' ast Block ,
4371+ is_loop : bool ,
4372+ ) {
4373+ self . with_resolved_label ( label, id, is_loop, block. span , |this| this. visit_block ( block) ) ;
43584374 }
43594375
43604376 fn resolve_block ( & mut self , block : & ' ast Block ) {
@@ -4497,10 +4513,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
44974513
44984514 ExprKind :: Break ( Some ( label) , _) | ExprKind :: Continue ( Some ( label) ) => {
44994515 match self . resolve_label ( label. ident ) {
4500- Ok ( ( node_id , _) ) => {
4516+ Ok ( ( node , _) ) => {
45014517 // Since this res is a label, it is never read.
4502- self . r . label_res_map . insert ( expr. id , node_id ) ;
4503- self . diag_metadata . unused_labels . remove ( & node_id ) ;
4518+ self . r . label_res_map . insert ( expr. id , node ) ;
4519+ self . diag_metadata . unused_labels . remove ( & node . 0 ) ;
45044520 }
45054521 Err ( error) => {
45064522 self . report_error ( label. ident . span , error) ;
@@ -4535,11 +4551,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
45354551 }
45364552
45374553 ExprKind :: Loop ( ref block, label, _) => {
4538- self . resolve_labeled_block ( label, expr. id , block)
4554+ self . resolve_labeled_block ( label, expr. id , block, true )
45394555 }
45404556
45414557 ExprKind :: While ( ref cond, ref block, label) => {
4542- self . with_resolved_label ( label, expr. id , |this| {
4558+ self . with_resolved_label ( label, expr. id , true , block . span , |this| {
45434559 this. with_rib ( ValueNS , RibKind :: Normal , |this| {
45444560 let old = this. diag_metadata . in_if_condition . replace ( cond) ;
45454561 this. visit_expr ( cond) ;
@@ -4553,11 +4569,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
45534569 self . visit_expr ( iter) ;
45544570 self . with_rib ( ValueNS , RibKind :: Normal , |this| {
45554571 this. resolve_pattern_top ( pat, PatternSource :: For ) ;
4556- this. resolve_labeled_block ( label, expr. id , body) ;
4572+ this. resolve_labeled_block ( label, expr. id , body, true ) ;
45574573 } ) ;
45584574 }
45594575
4560- ExprKind :: Block ( ref block, label) => self . resolve_labeled_block ( label, block. id , block) ,
4576+ ExprKind :: Block ( ref block, label) => {
4577+ self . resolve_labeled_block ( label, block. id , block, false )
4578+ }
45614579
45624580 // Equivalent to `visit::walk_expr` + passing some context to children.
45634581 ExprKind :: Field ( ref subexpression, _) => {
0 commit comments