Skip to content

Commit da8880d

Browse files
committed
Fix type alias being incorrectly marked as unused
Fixes rust-lang#42303
1 parent 5de0092 commit da8880d

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/librustc/middle/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,10 @@ struct DeadVisitor<'a, 'tcx: 'a> {
424424
impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
425425
fn should_warn_about_item(&mut self, item: &hir::Item) -> bool {
426426
let should_warn = match item.node {
427+
hir::ItemTy(ref ty, _) => self.live_symbols.contains(&ty.id),
427428
hir::ItemStatic(..)
428429
| hir::ItemConst(..)
429430
| hir::ItemFn(..)
430-
| hir::ItemTy(..)
431431
| hir::ItemEnum(..)
432432
| hir::ItemStruct(..)
433433
| hir::ItemUnion(..) => true,

src/test/run-pass/issue-42303.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![forbid(dead_code)]
12+
13+
// The most simple case: support one layer
14+
// Issue #42303 was originally reported about this issue
15+
mod a {
16+
pub struct Foo;
17+
18+
type Bar = Foo;
19+
20+
impl Bar {
21+
pub fn baz(&self) {}
22+
}
23+
}
24+
25+
// Multiple layers of re-defining,
26+
// to make sure we don't regress here
27+
mod b {
28+
pub struct Foo;
29+
30+
type Bar = Foo;
31+
type FooBar = Bar;
32+
type Baz = FooBar;
33+
type FooBarBaz = Baz;
34+
35+
impl FooBarBaz {
36+
pub fn baz(&self) {}
37+
}
38+
}
39+
40+
fn main() {
41+
a::Foo.baz();
42+
b::Foo.baz();
43+
}

0 commit comments

Comments
 (0)