@@ -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 > ,
@@ -2211,7 +2211,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
22112211
22122212 /// Searches the current set of local scopes for labels. Returns the `NodeId` of the resolved
22132213 /// label and reports an error if the label is not found or is unreachable.
2214- fn resolve_label ( & mut self , mut label : Ident ) -> Result < ( NodeId , Span ) , ResolutionError < ' a > > {
2214+ fn resolve_label (
2215+ & mut self ,
2216+ mut label : Ident ,
2217+ ) -> Result < ( ( NodeId , bool , Span ) , Span ) , ResolutionError < ' a > > {
22152218 let mut suggestion = None ;
22162219
22172220 for i in ( 0 ..self . label_ribs . len ( ) ) . rev ( ) {
@@ -4181,7 +4184,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
41814184 Ok ( Some ( result) )
41824185 }
41834186
4184- fn with_resolved_label ( & mut self , label : Option < Label > , id : NodeId , f : impl FnOnce ( & mut Self ) ) {
4187+ fn with_resolved_label (
4188+ & mut self ,
4189+ label : Option < Label > ,
4190+ id : NodeId ,
4191+ is_loop : bool ,
4192+ span : Span ,
4193+ f : impl FnOnce ( & mut Self ) ,
4194+ ) {
41854195 if let Some ( label) = label {
41864196 if label. ident . as_str ( ) . as_bytes ( ) [ 1 ] != b'_' {
41874197 self . diag_metadata . unused_labels . insert ( id, label. ident . span ) ;
@@ -4193,16 +4203,22 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
41934203
41944204 self . with_label_rib ( RibKind :: Normal , |this| {
41954205 let ident = label. ident . normalize_to_macro_rules ( ) ;
4196- this. label_ribs . last_mut ( ) . unwrap ( ) . bindings . insert ( ident, id ) ;
4206+ this. label_ribs . last_mut ( ) . unwrap ( ) . bindings . insert ( ident, ( id , is_loop , span ) ) ;
41974207 f ( this) ;
41984208 } ) ;
41994209 } else {
42004210 f ( self ) ;
42014211 }
42024212 }
42034213
4204- fn resolve_labeled_block ( & mut self , label : Option < Label > , id : NodeId , block : & ' ast Block ) {
4205- self . with_resolved_label ( label, id, |this| this. visit_block ( block) ) ;
4214+ fn resolve_labeled_block (
4215+ & mut self ,
4216+ label : Option < Label > ,
4217+ id : NodeId ,
4218+ block : & ' ast Block ,
4219+ is_loop : bool ,
4220+ ) {
4221+ self . with_resolved_label ( label, id, is_loop, block. span , |this| this. visit_block ( block) ) ;
42064222 }
42074223
42084224 fn resolve_block ( & mut self , block : & ' ast Block ) {
@@ -4345,10 +4361,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43454361
43464362 ExprKind :: Break ( Some ( label) , _) | ExprKind :: Continue ( Some ( label) ) => {
43474363 match self . resolve_label ( label. ident ) {
4348- Ok ( ( node_id , _) ) => {
4364+ Ok ( ( node , _) ) => {
43494365 // Since this res is a label, it is never read.
4350- self . r . label_res_map . insert ( expr. id , node_id ) ;
4351- self . diag_metadata . unused_labels . remove ( & node_id ) ;
4366+ self . r . label_res_map . insert ( expr. id , node ) ;
4367+ self . diag_metadata . unused_labels . remove ( & node . 0 ) ;
43524368 }
43534369 Err ( error) => {
43544370 self . report_error ( label. ident . span , error) ;
@@ -4383,11 +4399,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43834399 }
43844400
43854401 ExprKind :: Loop ( ref block, label, _) => {
4386- self . resolve_labeled_block ( label, expr. id , block)
4402+ self . resolve_labeled_block ( label, expr. id , block, true )
43874403 }
43884404
43894405 ExprKind :: While ( ref cond, ref block, label) => {
4390- self . with_resolved_label ( label, expr. id , |this| {
4406+ self . with_resolved_label ( label, expr. id , true , block . span , |this| {
43914407 this. with_rib ( ValueNS , RibKind :: Normal , |this| {
43924408 let old = this. diag_metadata . in_if_condition . replace ( cond) ;
43934409 this. visit_expr ( cond) ;
@@ -4401,11 +4417,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
44014417 self . visit_expr ( iter) ;
44024418 self . with_rib ( ValueNS , RibKind :: Normal , |this| {
44034419 this. resolve_pattern_top ( pat, PatternSource :: For ) ;
4404- this. resolve_labeled_block ( label, expr. id , body) ;
4420+ this. resolve_labeled_block ( label, expr. id , body, true ) ;
44054421 } ) ;
44064422 }
44074423
4408- ExprKind :: Block ( ref block, label) => self . resolve_labeled_block ( label, block. id , block) ,
4424+ ExprKind :: Block ( ref block, label) => {
4425+ self . resolve_labeled_block ( label, block. id , block, false )
4426+ }
44094427
44104428 // Equivalent to `visit::walk_expr` + passing some context to children.
44114429 ExprKind :: Field ( ref subexpression, _) => {
0 commit comments