Rollup merge of #77073 - lcnr:ty-trait-param, r=matthewjasper
dead_code: look at trait impls even if they don't contain items fixes #70225
This commit is contained in:
commit
ba44e9fe34
3 changed files with 44 additions and 1 deletions
|
@ -369,7 +369,7 @@ fn has_allow_dead_code_or_lang_attr(
|
||||||
// - This is because lang items are always callable from elsewhere.
|
// - This is because lang items are always callable from elsewhere.
|
||||||
// or
|
// or
|
||||||
// 2) We are not sure to be live or not
|
// 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> {
|
struct LifeSeeder<'k, 'tcx> {
|
||||||
worklist: Vec<hir::HirId>,
|
worklist: Vec<hir::HirId>,
|
||||||
krate: &'k hir::Crate<'k>,
|
krate: &'k hir::Crate<'k>,
|
||||||
|
@ -415,6 +415,9 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::Impl { ref of_trait, items, .. } => {
|
hir::ItemKind::Impl { ref of_trait, items, .. } => {
|
||||||
|
if of_trait.is_some() {
|
||||||
|
self.worklist.push(item.hir_id);
|
||||||
|
}
|
||||||
for impl_item_ref in items {
|
for impl_item_ref in items {
|
||||||
let impl_item = self.krate.impl_item(impl_item_ref.id);
|
let impl_item = self.krate.impl_item(impl_item_ref.id);
|
||||||
if of_trait.is_some()
|
if of_trait.is_some()
|
||||||
|
|
21
src/test/ui/const-generics/issues/issue-70225.rs
Normal file
21
src/test/ui/const-generics/issues/issue-70225.rs
Normal file
|
@ -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
src/test/ui/lint/dead-code/trait-impl.rs
Normal file
19
src/test/ui/lint/dead-code/trait-impl.rs
Normal file
|
@ -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] {}
|
Loading…
Add table
Add a link
Reference in a new issue