Skip to content
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

dead_code: look at trait impls even if they don't contain items #77073

Merged
merged 1 commit into from
Sep 25, 2020
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
5 changes: 4 additions & 1 deletion compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ fn has_allow_dead_code_or_lang_attr(
// - This is because lang items are always callable from elsewhere.
// or
// 2) We are not sure to be live or not
// * Implementation of a trait method
// * Implementations of traits and trait methods
struct LifeSeeder<'k, 'tcx> {
worklist: Vec<hir::HirId>,
krate: &'k hir::Crate<'k>,
Expand Down Expand Up @@ -415,6 +415,9 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
}
}
hir::ItemKind::Impl { ref of_trait, items, .. } => {
if of_trait.is_some() {
self.worklist.push(item.hir_id);
}
for impl_item_ref in items {
let impl_item = self.krate.impl_item(impl_item_ref.id);
if of_trait.is_some()
Expand Down
21 changes: 21 additions & 0 deletions src/test/ui/const-generics/issues/issue-70225.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// check-pass
#![feature(const_generics)]
#![allow(incomplete_features)]
#![deny(dead_code)]

// We previously incorrectly linted `L` as unused here.
const L: usize = 3;

fn main() {
let p = Printer {};
p.print();
}

trait Print<const N: usize> {
fn print(&self) -> usize {
3
}
}

struct Printer {}
impl Print<L> for Printer {}
19 changes: 19 additions & 0 deletions src/test/ui/lint/dead-code/trait-impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check-pass
#![deny(dead_code)]

enum Foo {
Bar,
}

fn main() {
let p = [0; 0];
p.bar();
}

trait Bar {
fn bar(&self) -> usize {
3
}
}

impl Bar for [u32; Foo::Bar as usize] {}