-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.L-dead_codeLint: dead_codeLint: dead_codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
#[allow(dead_code)]
struct Foo;
impl Foo {
fn foo(&self) {}
}Current output
warning: method `foo` is never used
--> src/lib.rs:5:8
|
4 | impl Foo {
| -------- method in this implementation
5 | fn foo(&self) {}
| ^^^
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by defaultDesired output
No warningRationale and extra context
Allowing on the impl block can suppress warning both on methods and types.
struct Foo;
#[allow(dead_code)]
impl Foo {
fn foo(&self) {}
}
But I think it's more intuitive to just allow on types.
Futhermore, considering that when we have dead types, no methods could be used. So maybe we can also suppress warnings for items in the impl block when there has been warnings for the type. 🤔
Other cases
Rust Version
Build using the Nightly version: 1.93.0-nightly
(2025-11-19 07bdbaedc63094281483)Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.L-dead_codeLint: dead_codeLint: dead_codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.