No dead code for types that implement traits that construct or read from them

struct Test(bool);

impl AsRef<bool> for Test {
    fn as_ref(&self) -> &bool {
        &self.0
    }
}

impl From<bool> for Test {
    fn from(value: bool) -> Self {
        Self { 0: value }
    }
}

fn main() {}
   Compiling playground v0.0.1 (/playground)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.74s

Why is there no dead_code warning (never constructed, never read)?
There should be.

In general, dead code analysis doesn‘t look at whether a trait implementation is used. Certainly doing so would be an improvement, but it's a hard problem.

1 Like