False positive: "struct is never used", but it is used via associated constant from a trait

21be280
Opened by Alex Kladov at 2024-12-21 04:50:14
trait X {
  const X: usize;
}

struct A;
struct B;

impl X for A {
  const X: usize = 0;
}

impl X for B {
  const X: usize = 1;
}

fn main() {
  let x = 1;
  match x {
    A::X => println!("A"),
    B::X => println!("B"),
    _ => println!("?"),
  }
}
λ rustc main.rs                                                                                                                     ~/trash
warning: struct is never used: `A`
 --> main.rs:5:1
  |
5 | struct A;
  | ^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

warning: struct is never used: `B`
 --> main.rs:6:1
  |
6 | struct B;

Looks like a false positive?

  1. The message now says:

    warning: struct is never constructed: `A`
    

    which is correct (but possibly still not desirable).

    varkor at 2019-04-22 20:42:16