about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKyle Stachowicz <kylestach99@gmail.com>2018-05-15 20:32:43 -0700
committerKyle Stachowicz <kylestach99@gmail.com>2018-05-18 16:57:15 -0700
commit4de4e6186417489b37bc73c064b35effe7e4409a (patch)
treec2b1cc1a5670bf169a9228bdf2b5115b6dc1cd0e
parent0f274122eef3c69c09c406dff32d695fca5509b3 (diff)
downloadrust-4de4e6186417489b37bc73c064b35effe7e4409a.tar.gz
rust-4de4e6186417489b37bc73c064b35effe7e4409a.zip
Fix ignored unused outer label when inner label shadows and is broken multiple times
-rw-r--r--src/librustc_lint/unused.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs
index 61c0485f886..f55a37697bc 100644
--- a/src/librustc_lint/unused.rs
+++ b/src/librustc_lint/unused.rs
@@ -472,7 +472,7 @@ declare_lint! {
 }
 
 #[derive(Clone)]
-pub struct UnusedLabel(pub Vec<ast::Label>);
+pub struct UnusedLabel(pub Vec<(ast::Label, bool)>);
 
 impl UnusedLabel {
     pub fn new() -> Self {
@@ -493,11 +493,11 @@ impl EarlyLintPass for UnusedLabel {
             | ast::ExprKind::WhileLet(_, _, _, Some(label))
             | ast::ExprKind::ForLoop(_, _, _, Some(label))
             | ast::ExprKind::Loop(_, Some(label)) => {
-                self.0.push(label);
+                self.0.push((label, false));
             }
             ast::ExprKind::Break(Some(label), _) | ast::ExprKind::Continue(Some(label)) => {
-                if let Some(index) = self.0.iter().rposition(|&l| l.ident == label.ident) {
-                    self.0.remove(index);
+                if let Some((_, ref mut was_used)) = self.0.iter_mut().rev().find(|(l, _)| label == *l) {
+                    *was_used = true;
                 }
             }
             _ => {}
@@ -510,11 +510,9 @@ impl EarlyLintPass for UnusedLabel {
             | ast::ExprKind::WhileLet(_, _, _, Some(label))
             | ast::ExprKind::ForLoop(_, _, _, Some(label))
             | ast::ExprKind::Loop(_, Some(label)) => {
-                if let Some(unused_label) = self.0.pop() {
-                    if label.ident == unused_label.ident {
+                if let Some((_, was_used)) = self.0.pop() {
+                    if !was_used {
                         ctxt.span_lint(UNUSED_LABEL, label.ident.span, "unused label");
-                    } else {
-                        self.0.push(unused_label);
                     }
                 }
             },