Skip to content

Suppress warnings on dead inherent methods when allowing dead types #149142

Description

@mu001999

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 default

Desired output

No warning

Rationale 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.L-dead_codeLint: dead_codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions