Skip to content

type alias incorrectly flagged as unused when solely used in impl header #58593

Open
@pnkfelix

Description

@pnkfelix

Consider the following code (play):

type T = ();

struct S<X>(X); 

impl Clone for S<T> { fn clone(&self) -> Self { S(()) } }

fn main() {
    let s = S(());
    drop(s.clone());
}

Today this emits the following warning diagnostic:

warning: type alias is never used: `T`
 --> src/main.rs:1:1
  |
1 | type T = ();
  | ^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

But that type alias is not dead code. It is used in the impl Clone for S<T> { ... }, as one can see by trying to recompile the code after commenting out the type alias.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-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