Skip to content

Commit c1be949

Browse files
committed
Impls and impl items inherit lint levels of the corresponding traits and trait items
1 parent cd43430 commit c1be949

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

compiler/rustc_passes/src/dead.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,15 @@ fn maybe_record_as_seed<'tcx>(
759759
match tcx.def_kind(parent) {
760760
DefKind::Impl { of_trait: false } | DefKind::Trait => {}
761761
DefKind::Impl { of_trait: true } => {
762+
if let Some(trait_item_def_id) =
763+
tcx.associated_item(owner_id.def_id).trait_item_def_id
764+
&& let Some(trait_item_local_def_id) = trait_item_def_id.as_local()
765+
&& let Some(comes_from_allow) =
766+
has_allow_dead_code_or_lang_attr(tcx, trait_item_local_def_id)
767+
{
768+
worklist.push((owner_id.def_id, comes_from_allow));
769+
}
770+
762771
// We only care about associated items of traits,
763772
// because they cannot be visited directly,
764773
// so we later mark them as live if their corresponding traits
@@ -772,6 +781,15 @@ fn maybe_record_as_seed<'tcx>(
772781
}
773782
DefKind::Impl { of_trait: true } => {
774783
if allow_dead_code.is_none() {
784+
if let Some(trait_def_id) = tcx
785+
.impl_trait_ref(owner_id.def_id)
786+
.and_then(|trait_ref| trait_ref.skip_binder().def_id.as_local())
787+
&& let Some(comes_from_allow) =
788+
has_allow_dead_code_or_lang_attr(tcx, trait_def_id)
789+
{
790+
worklist.push((owner_id.def_id, comes_from_allow));
791+
}
792+
775793
unsolved_items.push(owner_id.def_id);
776794
}
777795
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ check-pass
2+
3+
#![deny(dead_code)]
4+
5+
#[allow(dead_code)]
6+
trait Foo {
7+
const FOO: u32;
8+
type Baz;
9+
fn foobar();
10+
}
11+
12+
const fn bar(x: u32) -> u32 {
13+
x
14+
}
15+
16+
struct Qux;
17+
18+
struct FooBar;
19+
20+
impl Foo for u32 {
21+
const FOO: u32 = bar(0);
22+
type Baz = Qux;
23+
24+
fn foobar() {
25+
let _ = FooBar;
26+
}
27+
}
28+
29+
fn main() {}

0 commit comments

Comments
 (0)