Can one selectively lint if a variant of a public enum is never constructed within the crate, similarly to how the dead_code
diagnostic does it for a private enum?
pub enum MyError {
Overflow,
Bar,
Baz,
}
type MyResult<T> = Result<T, MyError>;
pub fn my_baz(input: u32) -> MyResult<u32> {
input.checked_add(1).ok_or(MyError::Overflow)
}
Output for the code above is empty, as expected. But, for enums which are public but are unlikely to be constructed outside the crate, like this ErrorKind
-like example, this would be useful to e.g. clean up unused error variants during development (in this case, Bar
and Baz
).
There's a workaround: changing pub enum
to private works, dead_code
kicks in and rustc warns about each unused variant, but there's also going to be one compile error for each "private type in public interface" (potentially a *lot*), so I wonder if there's a nicer way to do this.