rust-lang / rust-lang/rust

`From<PrivateType> for PublicExternalType` suppresses `dead_code`

Open
#157,961 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug L-dead_code L-false-negative needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

I tried this code:

mod private_module {
    pub struct UsedType;

    // This single line suppresses dead_code for ALL pub methods on UsedType.
    // Comment it out to see the warning on dead_pub_method.
    impl From<UsedType> for String {
        fn from(_: UsedType) -> String {
            String::new()
        }
    }

    impl UsedType {
        // This is never called — but NO warning because of the From impl above
        pub fn dead_pub_method(&self) -> u32 {
            42
        }

        pub fn called_method(&self) -> u32 {
            1
        }
    }
}

pub fn use_it() -> u32 {
    let x = private_module::UsedType;
    x.called_method()
}

I expected to see this happen: the Rust compiler warning about the unused function.

Instead, this happened: no warning.

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

Reproduce the behavior with the Rust code in the report and trace how the dead_code lint handles the From implementation. Add a regression test that warns about dead_pub_method while accepting called_method, then run the relevant compiler test suite.

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
Quiet
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.