Skip to content

Visit impl Trait for dead_code lint #59129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<'_, '_, '_>,
Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/lint/lint-dead-code-impl-trait.rs
Original file line number Diff line number Diff line change
@@ -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();
}
14 changes: 14 additions & 0 deletions src/test/ui/lint/lint-dead-code-impl-trait.stderr
Original file line number Diff line number Diff line change
@@ -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