Skip to content

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

Closed

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.

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    on Feb 20, 2019
  2. oli-obk commented on Feb 20, 2019

    @oli-obk
    Contributor
  3. self-assigned this
    on Mar 28, 2019
  4. varkor commented on Mar 29, 2019

    @varkor
    Contributor

    I think this is essentially the same problem as #59333 (comment).

  5. removed their assignment
    on Jun 10, 2019
  6. istankovic commented on Oct 20, 2023

    @istankovic
    Contributor

    Seems to be fixed. Tested with 1.73 and got no warnings.

  7. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Oct 20, 2023
  8. KaiTomotake commented on Jan 23, 2026

    @KaiTomotake
    Contributor

    @rustbot claim

  9. KaiTomotake commented on Jan 23, 2026

    @KaiTomotake
    Contributor

    Oops, looks like there was already someone ahead of me.
    tests/ui/lint/dead-code/alias-type-used-as-generic-arg-in-impl.rs

  10. zakrad commented on Sep 21, 2026

    @zakrad
    Contributor

    This looks covereed by tests/ui/lint/dead-code/alias-type-used-as-generic-arg-in-impl.rs added in #141407 can be closed.

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

Metadata

Metadata

Assignees

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