@@ -669,7 +669,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
669
669
last_block_rib : Option < Rib < ' a > > ,
670
670
671
671
/// The current set of local scopes, for labels.
672
- label_ribs : Vec < Rib < ' a , NodeId > > ,
672
+ label_ribs : Vec < Rib < ' a , ( NodeId , bool , Span ) > > ,
673
673
674
674
/// The current set of local scopes for lifetimes.
675
675
lifetime_ribs : Vec < LifetimeRib > ,
@@ -2313,7 +2313,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2313
2313
2314
2314
/// Searches the current set of local scopes for labels. Returns the `NodeId` of the resolved
2315
2315
/// 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 > > {
2317
2320
let mut suggestion = None ;
2318
2321
2319
2322
for i in ( 0 ..self . label_ribs . len ( ) ) . rev ( ) {
@@ -4330,7 +4333,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4330
4333
Ok ( Some ( result) )
4331
4334
}
4332
4335
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
+ ) {
4334
4344
if let Some ( label) = label {
4335
4345
if label. ident . as_str ( ) . as_bytes ( ) [ 1 ] != b'_' {
4336
4346
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> {
4342
4352
4343
4353
self . with_label_rib ( RibKind :: Normal , |this| {
4344
4354
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 ) ) ;
4346
4356
f ( this) ;
4347
4357
} ) ;
4348
4358
} else {
4349
4359
f ( self ) ;
4350
4360
}
4351
4361
}
4352
4362
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) ) ;
4355
4371
}
4356
4372
4357
4373
fn resolve_block ( & mut self , block : & ' ast Block ) {
@@ -4494,10 +4510,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4494
4510
4495
4511
ExprKind :: Break ( Some ( label) , _) | ExprKind :: Continue ( Some ( label) ) => {
4496
4512
match self . resolve_label ( label. ident ) {
4497
- Ok ( ( node_id , _) ) => {
4513
+ Ok ( ( node , _) ) => {
4498
4514
// 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 ) ;
4501
4517
}
4502
4518
Err ( error) => {
4503
4519
self . report_error ( label. ident . span , error) ;
@@ -4532,11 +4548,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4532
4548
}
4533
4549
4534
4550
ExprKind :: Loop ( ref block, label, _) => {
4535
- self . resolve_labeled_block ( label, expr. id , block)
4551
+ self . resolve_labeled_block ( label, expr. id , block, true )
4536
4552
}
4537
4553
4538
4554
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| {
4540
4556
this. with_rib ( ValueNS , RibKind :: Normal , |this| {
4541
4557
let old = this. diag_metadata . in_if_condition . replace ( cond) ;
4542
4558
this. visit_expr ( cond) ;
@@ -4550,11 +4566,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4550
4566
self . visit_expr ( iter) ;
4551
4567
self . with_rib ( ValueNS , RibKind :: Normal , |this| {
4552
4568
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 ) ;
4554
4570
} ) ;
4555
4571
}
4556
4572
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
+ }
4558
4576
4559
4577
// Equivalent to `visit::walk_expr` + passing some context to children.
4560
4578
ExprKind :: Field ( ref subexpression, _) => {
0 commit comments