Remove unused enum variants from thiserror enum

I use the thirserror lib a lot, and often I accumulate errors that I don't use anymore.

#[derive(Debug, Error]
pub enum MyError{
#[error("{}", .0)]
MyError1
}

is there a tool that looks into this MyError and removes the MyError1 if no one instantiates it?

1 Like

If your crate is published on crates.io and in use by other people then, in general, you won't be able to find out if MyError1 is being used. You could check out your crate's reverse dependencies tab to see what other published crates use your code and check their repos one-by-one to give you a conservative estimate, but that could be tedious.

However, if it is mostly an internal thing, it could be as simple as removing the variant and seeing how much code breaks. For a less destructive method, you could add a #[deprecated] attribute and see what warnings pop up.

4 Likes