diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 84ead6506c85c..4c8c5ae7d2043 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -424,10 +424,10 @@ struct DeadVisitor<'a, 'tcx: 'a> { impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { fn should_warn_about_item(&mut self, item: &hir::Item) -> bool { let should_warn = match item.node { + hir::ItemTy(ref ty, _) => self.live_symbols.contains(&ty.id), hir::ItemStatic(..) | hir::ItemConst(..) | hir::ItemFn(..) - | hir::ItemTy(..) | hir::ItemEnum(..) | hir::ItemStruct(..) | hir::ItemUnion(..) => true, diff --git a/src/test/run-pass/issue-42303.rs b/src/test/run-pass/issue-42303.rs new file mode 100644 index 0000000000000..e3f36af92d6f6 --- /dev/null +++ b/src/test/run-pass/issue-42303.rs @@ -0,0 +1,43 @@ +// Copyright 2017 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. + +#![forbid(dead_code)] + +// The most simple case: support one layer +// Issue #42303 was originally reported about this issue +mod a { + pub struct Foo; + + type Bar = Foo; + + impl Bar { + pub fn baz(&self) {} + } +} + +// Multiple layers of re-defining, +// to make sure we don't regress here +mod b { + pub struct Foo; + + type Bar = Foo; + type FooBar = Bar; + type Baz = FooBar; + type FooBarBaz = Baz; + + impl FooBarBaz { + pub fn baz(&self) {} + } +} + +fn main() { + a::Foo.baz(); + b::Foo.baz(); +}