rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.25k stars 12.71k forks source link

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

Open pnkfelix opened 5 years ago

pnkfelix commented 5 years ago

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.

oli-obk commented 5 years ago

Previous instances of related (or possibly the same) problems:

varkor commented 5 years ago

I think this is essentially the same problem as https://github.com/rust-lang/rust/issues/59333#issuecomment-477820887.

istankovic commented 1 year ago

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