@@ -672,7 +672,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
672
672
last_block_rib : Option < Rib < ' a > > ,
673
673
674
674
/// The current set of local scopes, for labels.
675
- label_ribs : Vec < Rib < ' a , NodeId > > ,
675
+ label_ribs : Vec < Rib < ' a , ( NodeId , bool , Span ) > > ,
676
676
677
677
/// The current set of local scopes for lifetimes.
678
678
lifetime_ribs : Vec < LifetimeRib > ,
@@ -2316,7 +2316,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2316
2316
2317
2317
/// Searches the current set of local scopes for labels. Returns the `NodeId` of the resolved
2318
2318
/// 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 > > {
2320
2323
let mut suggestion = None ;
2321
2324
2322
2325
for i in ( 0 ..self . label_ribs . len ( ) ) . rev ( ) {
@@ -4333,7 +4336,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4333
4336
Ok ( Some ( result) )
4334
4337
}
4335
4338
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
+ ) {
4337
4347
if let Some ( label) = label {
4338
4348
if label. ident . as_str ( ) . as_bytes ( ) [ 1 ] != b'_' {
4339
4349
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> {
4345
4355
4346
4356
self . with_label_rib ( RibKind :: Normal , |this| {
4347
4357
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 ) ) ;
4349
4359
f ( this) ;
4350
4360
} ) ;
4351
4361
} else {
4352
4362
f ( self ) ;
4353
4363
}
4354
4364
}
4355
4365
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) ) ;
4358
4374
}
4359
4375
4360
4376
fn resolve_block ( & mut self , block : & ' ast Block ) {
@@ -4497,10 +4513,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4497
4513
4498
4514
ExprKind :: Break ( Some ( label) , _) | ExprKind :: Continue ( Some ( label) ) => {
4499
4515
match self . resolve_label ( label. ident ) {
4500
- Ok ( ( node_id , _) ) => {
4516
+ Ok ( ( node , _) ) => {
4501
4517
// 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 ) ;
4504
4520
}
4505
4521
Err ( error) => {
4506
4522
self . report_error ( label. ident . span , error) ;
@@ -4535,11 +4551,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4535
4551
}
4536
4552
4537
4553
ExprKind :: Loop ( ref block, label, _) => {
4538
- self . resolve_labeled_block ( label, expr. id , block)
4554
+ self . resolve_labeled_block ( label, expr. id , block, true )
4539
4555
}
4540
4556
4541
4557
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| {
4543
4559
this. with_rib ( ValueNS , RibKind :: Normal , |this| {
4544
4560
let old = this. diag_metadata . in_if_condition . replace ( cond) ;
4545
4561
this. visit_expr ( cond) ;
@@ -4553,11 +4569,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4553
4569
self . visit_expr ( iter) ;
4554
4570
self . with_rib ( ValueNS , RibKind :: Normal , |this| {
4555
4571
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 ) ;
4557
4573
} ) ;
4558
4574
}
4559
4575
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
+ }
4561
4579
4562
4580
// Equivalent to `visit::walk_expr` + passing some context to children.
4563
4581
ExprKind :: Field ( ref subexpression, _) => {
0 commit comments