Skip to content

Commit 4de4e61

Browse files
committed
Fix ignored unused outer label when inner label shadows and is broken multiple times
1 parent 0f27412 commit 4de4e61

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/librustc_lint/unused.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ declare_lint! {
472472
}
473473

474474
#[derive(Clone)]
475-
pub struct UnusedLabel(pub Vec<ast::Label>);
475+
pub struct UnusedLabel(pub Vec<(ast::Label, bool)>);
476476

477477
impl UnusedLabel {
478478
pub fn new() -> Self {
@@ -493,11 +493,11 @@ impl EarlyLintPass for UnusedLabel {
493493
| ast::ExprKind::WhileLet(_, _, _, Some(label))
494494
| ast::ExprKind::ForLoop(_, _, _, Some(label))
495495
| ast::ExprKind::Loop(_, Some(label)) => {
496-
self.0.push(label);
496+
self.0.push((label, false));
497497
}
498498
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;
501501
}
502502
}
503503
_ => {}
@@ -510,11 +510,9 @@ impl EarlyLintPass for UnusedLabel {
510510
| ast::ExprKind::WhileLet(_, _, _, Some(label))
511511
| ast::ExprKind::ForLoop(_, _, _, Some(label))
512512
| 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 {
515515
ctxt.span_lint(UNUSED_LABEL, label.ident.span, "unused label");
516-
} else {
517-
self.0.push(unused_label);
518516
}
519517
}
520518
},

0 commit comments

Comments
 (0)