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)]

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 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.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.