Check what file uses what import?

I have put all my imports in my main.rs. My project has multiple files and modules.

I think it'd be cleaner to import libraries who are only used by a specific file/module only in the relevant module-file.

Is there a fast way to check what import belongs in what module/file? I tried cargo tree but that output wasn't really useful.

I'm not entirely sure what you've done or what you're asking, but if you're trying to clean up uses, you can copy+paste all of them into each module, let the editor flag unused imports, then delete them until it stops complaining. Heck, cargo fix might even be able to do the "clean up" part for you, but I've never used it myself.

The only way modules could be using the imports from main.rs is via use super::something_here or use crate:: something_here, otherwise they'd have to import directly (which may be what you're asking?)
If that's the case, then removing all super and crate imports for items not defined in your crate may help.

1 Like

Remove all the imports from your main.rs and follow the compiler errors :slight_smile:

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.