Skip to content
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
13 changes: 5 additions & 8 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/lint/dead-code/allow-adt-propagation-to-impls.rs
Original file line number Diff line number Diff line change
@@ -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

@mu001999 mu001999 Aug 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should success only after #157885.

View changes since the review


fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/lint/dead-code/allow-adt-propagation-to-impls.stderr
Original file line number Diff line number Diff line change
@@ -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

Loading