I'm working on a large (~750 files, > 400k LoC) crate, which overuses pub. Pretty much every struct and method is pub. The crate is a library, so the compiler doesn't warn when an item isn't used. What process would you follow to reduce the visibility of items?
I was thiking of:
turning every pub fn, pub struct and pub enum into pub(crate) fn, pub(crate) struct, pub(crate) enum, then try to build the crates that uses the library, so see exactly what really needs to be pub.
then turn the pub(crate) into pub(super) and restore pub(crate) where there are errors
then remove the pub(super) and restore it where there are errors
But this is going to be pretty tedious process. Is there a better way to do that?
I'm a big believer in the "glutton for punishment" way of doing this:
Make sure the existing crates compile without warnings, and that cargo clippy does not show anything (for all the crates in the set you care about, not just the one with excessive visibility).
Remove pub completely, breaking everything, from the crate you're fixing.
Make the crate compile without warnings on its own by adding pub in places where it's needed
Fix up cargo clippy so that there's no clippy warnings from making things not pub.
Repeat steps 3 and 4 for each dependent crate, until you have everything working again.