Rollup merge of #59129 - sanxiyn:visit-impl-trait, r=varkor

Visit impl Trait for dead_code lint

Fix #59085.
This commit is contained in:
Mazdak Farrokhzad 2019-03-13 03:33:53 +01:00 committed by GitHub
commit b70a98f261
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 1 deletions

View File

@ -3,7 +3,7 @@
// from live codes are live, and everything else is dead.
use crate::hir::Node;
use crate::hir::{self, PatKind};
use crate::hir::{self, PatKind, TyKind};
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
use crate::hir::itemlikevisit::ItemLikeVisitor;
@ -282,6 +282,17 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
self.handle_definition(path.def);
intravisit::walk_path(self, path);
}
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
match ty.node {
TyKind::Def(item_id, _) => {
let item = self.tcx.hir().expect_item(item_id.id);
intravisit::walk_item(self, item);
}
_ => ()
}
intravisit::walk_ty(self, ty);
}
}
fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>,

View File

@ -0,0 +1,18 @@
#![deny(dead_code)]
trait Trait {
type Type;
}
impl Trait for () {
type Type = ();
}
type Used = ();
type Unused = (); //~ ERROR type alias is never used
fn foo() -> impl Trait<Type = Used> {}
fn main() {
foo();
}

View File

@ -0,0 +1,14 @@
error: type alias is never used: `Unused`
--> $DIR/lint-dead-code-impl-trait.rs:12:1
|
LL | type Unused = ();
| ^^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/lint-dead-code-impl-trait.rs:1:9
|
LL | #![deny(dead_code)]
| ^^^^^^^^^
error: aborting due to previous error