@@ -472,7 +472,7 @@ declare_lint! {
472
472
}
473
473
474
474
#[ derive( Clone ) ]
475
- pub struct UnusedLabel ( pub Vec < ast:: Label > ) ;
475
+ pub struct UnusedLabel ( pub Vec < ( ast:: Label , bool ) > ) ;
476
476
477
477
impl UnusedLabel {
478
478
pub fn new ( ) -> Self {
@@ -493,11 +493,11 @@ impl EarlyLintPass for UnusedLabel {
493
493
| ast:: ExprKind :: WhileLet ( _, _, _, Some ( label) )
494
494
| ast:: ExprKind :: ForLoop ( _, _, _, Some ( label) )
495
495
| ast:: ExprKind :: Loop ( _, Some ( label) ) => {
496
- self . 0 . push ( label) ;
496
+ self . 0 . push ( ( label, false ) ) ;
497
497
}
498
498
ast:: ExprKind :: Break ( Some ( label) , _) | ast:: ExprKind :: Continue ( Some ( label) ) => {
499
- if let Some ( index ) = self . 0 . iter ( ) . rposition ( | & l| l . ident == label . ident ) {
500
- self . 0 . remove ( index ) ;
499
+ if let Some ( ( _ , ref mut was_used ) ) = self . 0 . iter_mut ( ) . rev ( ) . find ( | ( l , _ ) | label == * l ) {
500
+ * was_used = true ;
501
501
}
502
502
}
503
503
_ => { }
@@ -510,11 +510,9 @@ impl EarlyLintPass for UnusedLabel {
510
510
| ast:: ExprKind :: WhileLet ( _, _, _, Some ( label) )
511
511
| ast:: ExprKind :: ForLoop ( _, _, _, Some ( label) )
512
512
| ast:: ExprKind :: Loop ( _, Some ( label) ) => {
513
- if let Some ( unused_label ) = self . 0 . pop ( ) {
514
- if label . ident == unused_label . ident {
513
+ if let Some ( ( _ , was_used ) ) = self . 0 . pop ( ) {
514
+ if !was_used {
515
515
ctxt. span_lint ( UNUSED_LABEL , label. ident . span , "unused label" ) ;
516
- } else {
517
- self . 0 . push ( unused_label) ;
518
516
}
519
517
}
520
518
} ,
0 commit comments