diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index d6a8b2c2f5eb6..637052eb87530 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -601,15 +601,12 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { { if defer_seeds_come_from_allow { return ImplItemCheckResult::Dead { require: adt_def_id }; - } else { - let comes_from_allow = trait_comes_from_allow - .or_else(|| has_allow_dead_code_or_lang_attr(self.tcx, adt_def_id)); - - return match comes_from_allow { - Some(comes_from_allow) => ImplItemCheckResult::Live(comes_from_allow), - None => ImplItemCheckResult::Dead { require: adt_def_id }, - }; } + + return match trait_comes_from_allow { + Some(comes_from_allow) => ImplItemCheckResult::Live(comes_from_allow), + None => ImplItemCheckResult::Dead { require: adt_def_id }, + }; } ImplItemCheckResult::Live(ComesFromAllowExpect::No) diff --git a/tests/ui/lint/dead-code/allow-adt-propagation-to-impls.rs b/tests/ui/lint/dead-code/allow-adt-propagation-to-impls.rs new file mode 100644 index 0000000000000..72d68c3e91396 --- /dev/null +++ b/tests/ui/lint/dead-code/allow-adt-propagation-to-impls.rs @@ -0,0 +1,18 @@ +#![deny(dead_code)] + +pub trait Tr { + fn foo(&self); +} + +#[allow(dead_code)] +struct Foo; + +impl Tr for Foo { + fn foo(&self) { + bar(); + } +} + +fn bar() {} //~ ERROR function `bar` is never used + +fn main() {} diff --git a/tests/ui/lint/dead-code/allow-adt-propagation-to-impls.stderr b/tests/ui/lint/dead-code/allow-adt-propagation-to-impls.stderr new file mode 100644 index 0000000000000..ba0fe951e4e59 --- /dev/null +++ b/tests/ui/lint/dead-code/allow-adt-propagation-to-impls.stderr @@ -0,0 +1,14 @@ +error: function `bar` is never used + --> $DIR/allow-adt-propagation-to-impls.rs:16:4 + | +LL | fn bar() {} + | ^^^ + | +note: the lint level is defined here + --> $DIR/allow-adt-propagation-to-impls.rs:1:9 + | +LL | #![deny(dead_code)] + | ^^^^^^^^^ + +error: aborting due to 1 previous error +