From ca129e376e16693e6974b813ab6fa0cc33e22387 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 9 Mar 2016 10:12:24 -0800 Subject: [PATCH] lint: mark associated types as live for the dead_code pass --- src/librustc/middle/dead.rs | 12 +++------ .../lint-dead-code-associated-type.rs | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 src/test/run-pass/lint-dead-code-associated-type.rs diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index f1b38ea8b81..4ceac287d19 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -351,15 +351,9 @@ impl<'v> Visitor<'v> for LifeSeeder { } hir::ItemImpl(_, _, _, ref opt_trait, _, ref impl_items) => { for impl_item in impl_items { - match impl_item.node { - hir::ImplItemKind::Const(..) | - hir::ImplItemKind::Method(..) => { - if opt_trait.is_some() || - has_allow_dead_code_or_lang_attr(&impl_item.attrs) { - self.worklist.push(impl_item.id); - } - } - hir::ImplItemKind::Type(_) => {} + if opt_trait.is_some() || + has_allow_dead_code_or_lang_attr(&impl_item.attrs) { + self.worklist.push(impl_item.id); } } } diff --git a/src/test/run-pass/lint-dead-code-associated-type.rs b/src/test/run-pass/lint-dead-code-associated-type.rs new file mode 100644 index 00000000000..1ae078ba221 --- /dev/null +++ b/src/test/run-pass/lint-dead-code-associated-type.rs @@ -0,0 +1,27 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![deny(dead_code)] + +trait Foo { + type Bar; +} + +struct Used; + +struct Ex; + +impl Foo for Ex { + type Bar = Used; +} + +pub fn main() { + let _x = Ex; +}