@@ -658,7 +658,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
658
658
last_block_rib : Option < Rib < ' a > > ,
659
659
660
660
/// The current set of local scopes, for labels.
661
- label_ribs : Vec < Rib < ' a , NodeId > > ,
661
+ label_ribs : Vec < Rib < ' a , ( NodeId , bool , Span ) > > ,
662
662
663
663
/// The current set of local scopes for lifetimes.
664
664
lifetime_ribs : Vec < LifetimeRib > ,
@@ -2211,7 +2211,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2211
2211
2212
2212
/// Searches the current set of local scopes for labels. Returns the `NodeId` of the resolved
2213
2213
/// 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 > > {
2215
2218
let mut suggestion = None ;
2216
2219
2217
2220
for i in ( 0 ..self . label_ribs . len ( ) ) . rev ( ) {
@@ -4181,7 +4184,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4181
4184
Ok ( Some ( result) )
4182
4185
}
4183
4186
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
+ ) {
4185
4195
if let Some ( label) = label {
4186
4196
if label. ident . as_str ( ) . as_bytes ( ) [ 1 ] != b'_' {
4187
4197
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> {
4193
4203
4194
4204
self . with_label_rib ( RibKind :: Normal , |this| {
4195
4205
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 ) ) ;
4197
4207
f ( this) ;
4198
4208
} ) ;
4199
4209
} else {
4200
4210
f ( self ) ;
4201
4211
}
4202
4212
}
4203
4213
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) ) ;
4206
4222
}
4207
4223
4208
4224
fn resolve_block ( & mut self , block : & ' ast Block ) {
@@ -4345,10 +4361,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4345
4361
4346
4362
ExprKind :: Break ( Some ( label) , _) | ExprKind :: Continue ( Some ( label) ) => {
4347
4363
match self . resolve_label ( label. ident ) {
4348
- Ok ( ( node_id , _) ) => {
4364
+ Ok ( ( node , _) ) => {
4349
4365
// 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 ) ;
4352
4368
}
4353
4369
Err ( error) => {
4354
4370
self . report_error ( label. ident . span , error) ;
@@ -4383,11 +4399,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4383
4399
}
4384
4400
4385
4401
ExprKind :: Loop ( ref block, label, _) => {
4386
- self . resolve_labeled_block ( label, expr. id , block)
4402
+ self . resolve_labeled_block ( label, expr. id , block, true )
4387
4403
}
4388
4404
4389
4405
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| {
4391
4407
this. with_rib ( ValueNS , RibKind :: Normal , |this| {
4392
4408
let old = this. diag_metadata . in_if_condition . replace ( cond) ;
4393
4409
this. visit_expr ( cond) ;
@@ -4401,11 +4417,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4401
4417
self . visit_expr ( iter) ;
4402
4418
self . with_rib ( ValueNS , RibKind :: Normal , |this| {
4403
4419
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 ) ;
4405
4421
} ) ;
4406
4422
}
4407
4423
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
+ }
4409
4427
4410
4428
// Equivalent to `visit::walk_expr` + passing some context to children.
4411
4429
ExprKind :: Field ( ref subexpression, _) => {
0 commit comments