Skip to content

Commit 438d229

Browse files
committed
dead_code: look at trait impls even if they don't contain items
1 parent e0bc267 commit 438d229

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

compiler/rustc_passes/src/dead.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ fn has_allow_dead_code_or_lang_attr(
369369
// - This is because lang items are always callable from elsewhere.
370370
// or
371371
// 2) We are not sure to be live or not
372-
// * Implementation of a trait method
372+
// * Implementations of traits and trait methods
373373
struct LifeSeeder<'k, 'tcx> {
374374
worklist: Vec<hir::HirId>,
375375
krate: &'k hir::Crate<'k>,
@@ -415,6 +415,9 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
415415
}
416416
}
417417
hir::ItemKind::Impl { ref of_trait, items, .. } => {
418+
if of_trait.is_some() {
419+
self.worklist.push(item.hir_id);
420+
}
418421
for impl_item_ref in items {
419422
let impl_item = self.krate.impl_item(impl_item_ref.id);
420423
if of_trait.is_some()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// check-pass
2+
#![feature(const_generics)]
3+
#![allow(incomplete_features)]
4+
#![deny(dead_code)]
5+
6+
// We previously incorrectly linted `L` as unused here.
7+
const L: usize = 3;
8+
9+
fn main() {
10+
let p = Printer {};
11+
p.print();
12+
}
13+
14+
trait Print<const N: usize> {
15+
fn print(&self) -> usize {
16+
3
17+
}
18+
}
19+
20+
struct Printer {}
21+
impl Print<L> for Printer {}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// check-pass
2+
#![deny(dead_code)]
3+
4+
enum Foo {
5+
Bar,
6+
}
7+
8+
fn main() {
9+
let p = [0; 0];
10+
p.bar();
11+
}
12+
13+
trait Bar {
14+
fn bar(&self) -> usize {
15+
3
16+
}
17+
}
18+
19+
impl Bar for [u32; Foo::Bar as usize] {}

0 commit comments

Comments
 (0)