I have some enum that maybe contain dead items in list, because of Display
impl, rust-analyzer does not highlight them.
Is any option to catch these options not in use?
I have some enum that maybe contain dead items in list, because of Display
impl, rust-analyzer does not highlight them.
Is any option to catch these options not in use?
The Display
implementation is not the problem why the compiler can't see that one of your variants is unused, it's because the enum is public. Any potential dependent might use the unused variant, so the compiler has to assume that even if you don't use it internally, you still put the variant there for any potential dependent crate to use. Hence it doesn't show any unused variant warnings. You can play around with the visibility of the enum using this playground to see for yourself:
// Try making this `pub` to get the `dead_code` warning to disappear
pub(crate) enum Foo {
Bar,
Baz,
Bat,
}
impl std::fmt::Display for Foo {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Bar => write!(f, "bar"),
Self::Baz => write!(f, "baz"),
Self::Bat => write!(f, "bat"),
}
}
}
fn main() {
let bar = Foo::Bar;
let baz = Foo::Baz;
println!("{bar}");
println!("{baz}");
}
Really, forgot about public keywords
will try to implement some checker by your example so, if it's nothing to derive
Thanks!
More specifically, it will separately check that there's at least one path to creating each value, and at least one path to reading/matching each value. It's just that exporting from a crate is implicitly both.