Skip to content

Commit 71c06a5

Browse files
committed
Auto merge of #38051 - sanxiyn:unused-type-alias-3, r=eddyb
Warn unused type aliases, reimplemented Reimplementation of #37631. Fix #37455.
2 parents 1f965cc + f71f31a commit 71c06a5

File tree

8 files changed

+32
-27
lines changed

8 files changed

+32
-27
lines changed

src/librustc/middle/dead.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
8686
}
8787
}
8888

89-
fn handle_definition(&mut self, id: ast::NodeId, def: Def) {
90-
// If `bar` is a trait item, make sure to mark Foo as alive in `Foo::bar`
91-
match def {
92-
Def::AssociatedTy(..) | Def::Method(_) | Def::AssociatedConst(_)
93-
if self.tcx.trait_of_item(def.def_id()).is_some() => {
94-
if let Some(substs) = self.tcx.tables().item_substs.get(&id) {
95-
if let ty::TyAdt(tyid, _) = substs.substs.type_at(0).sty {
96-
self.check_def_id(tyid.did);
97-
}
98-
}
99-
}
100-
_ => {}
101-
}
102-
89+
fn handle_definition(&mut self, def: Def) {
10390
match def {
10491
Def::Const(_) | Def::AssociatedConst(..) => {
10592
self.check_def_id(def.def_id());
@@ -241,7 +228,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
241228
match expr.node {
242229
hir::ExprPath(ref qpath @ hir::QPath::TypeRelative(..)) => {
243230
let def = self.tcx.tables().qpath_def(qpath, expr.id);
244-
self.handle_definition(expr.id, def);
231+
self.handle_definition(def);
245232
}
246233
hir::ExprMethodCall(..) => {
247234
self.lookup_and_handle_method(expr.id);
@@ -281,7 +268,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
281268
}
282269
PatKind::Path(ref qpath @ hir::QPath::TypeRelative(..)) => {
283270
let def = self.tcx.tables().qpath_def(qpath, pat.id);
284-
self.handle_definition(pat.id, def);
271+
self.handle_definition(def);
285272
}
286273
_ => ()
287274
}
@@ -291,8 +278,8 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
291278
self.ignore_non_const_paths = false;
292279
}
293280

294-
fn visit_path(&mut self, path: &'tcx hir::Path, id: ast::NodeId) {
295-
self.handle_definition(id, path.def);
281+
fn visit_path(&mut self, path: &'tcx hir::Path, _: ast::NodeId) {
282+
self.handle_definition(path.def);
296283
intravisit::walk_path(self, path);
297284
}
298285
}
@@ -426,6 +413,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
426413
hir::ItemStatic(..)
427414
| hir::ItemConst(..)
428415
| hir::ItemFn(..)
416+
| hir::ItemTy(..)
429417
| hir::ItemEnum(..)
430418
| hir::ItemStruct(..)
431419
| hir::ItemUnion(..) => true,

src/librustc_data_structures/graph/tests.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
use graph::*;
1212
use std::fmt::Debug;
1313

14-
type TestNode = Node<&'static str>;
15-
type TestEdge = Edge<&'static str>;
1614
type TestGraph = Graph<&'static str, &'static str>;
1715

1816
fn create_graph() -> TestGraph {

src/librustc_trans/back/msvc/registry.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::io;
1212
use std::ffi::{OsString, OsStr};
1313
use std::os::windows::prelude::*;
1414
use std::ptr;
15-
use libc::{c_void, c_long};
15+
use libc::c_long;
1616

1717
pub type DWORD = u32;
1818
type LPCWSTR = *const u16;
@@ -38,8 +38,6 @@ pub enum __HKEY__ {}
3838
pub type HKEY = *mut __HKEY__;
3939
pub type PHKEY = *mut HKEY;
4040
pub type REGSAM = DWORD;
41-
pub type LPWSTR = *mut u16;
42-
pub type PFILETIME = *mut c_void;
4341

4442
#[link(name = "advapi32")]
4543
extern "system" {

src/libstd/sys/windows/c.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ pub type CHAR = c_char;
4747
pub type HCRYPTPROV = LONG_PTR;
4848
pub type ULONG_PTR = c_ulonglong;
4949
pub type ULONG = c_ulong;
50+
#[cfg(target_arch = "x86_64")]
5051
pub type ULONGLONG = u64;
52+
#[cfg(target_arch = "x86_64")]
5153
pub type DWORDLONG = ULONGLONG;
5254

5355
pub type LPBOOL = *mut BOOL;
@@ -66,7 +68,6 @@ pub type LPVOID = *mut c_void;
6668
pub type LPWCH = *mut WCHAR;
6769
pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW;
6870
pub type LPWSADATA = *mut WSADATA;
69-
pub type LPWSAPROTOCOLCHAIN = *mut WSAPROTOCOLCHAIN;
7071
pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO;
7172
pub type LPWSTR = *mut WCHAR;
7273
pub type LPFILETIME = *mut FILETIME;
@@ -311,8 +312,6 @@ pub struct WSADATA {
311312
pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
312313
}
313314

314-
pub type WSAEVENT = HANDLE;
315-
316315
#[repr(C)]
317316
pub struct WSAPROTOCOL_INFO {
318317
pub dwServiceFlags1: DWORD,

src/test/compile-fail/issue-32119.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(rustc_attrs)]
12+
#![allow(dead_code)]
1213

1314
pub type T = ();
1415
mod foo { pub use super::T; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 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+
#![deny(dead_code)]
12+
13+
type Used = u8;
14+
type Unused = u8; //~ ERROR type alias is never used
15+
16+
fn id(x: Used) -> Used { x }
17+
18+
fn main() {
19+
id(0);
20+
}

src/test/compile-fail/macro-tt-matchers.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(rustc_attrs)]
12+
#![allow(dead_code)]
1213

1314
macro_rules! foo {
1415
($x:tt) => (type Alias = $x<i32>;)

src/tools/cargotest/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct Test {
2424
const TEST_REPOS: &'static [Test] = &[Test {
2525
name: "cargo",
2626
repo: "https://github.com/rust-lang/cargo",
27-
sha: "806e3c368a15f618244a3b4e918bf77f9c403fd0",
27+
sha: "b7be4f2ef2cf743492edc6dfb55d087ed88f2d76",
2828
lock: None,
2929
},
3030
Test {

0 commit comments

Comments
 (0)