rust-lang / rust-lang/rust

Suppress warnings on dead inherent methods when allowing dead types

Open
#149,142 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lints C-enhancement L-dead_code T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

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 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the minimal Rust reproduction with the reported Nightly version and compare the current diagnostic with the desired no-warning output. Investigate how dead-code warnings are emitted for methods in an impl of a type marked #[allow(dead_code)]; done means the shown case produces no warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.