Make Rust Analyzer check unused modules?

I'm adding new modules not yet used or even included in the project. For some reason I don't get compile errors or hints in the code that something is wrong until I explicitly use parts of the module in my application. Is this expected behavior or are there something I have misconfigured?

Can I change this somehow? I don't want to have to import unfinished code just to get feedback from rust analyzer.

Modules need to be "mounted" with mod in order to be checked, because imports/paths are dependent on what crate the module is mounted to (e.g. what crate crate:: is, what external crates are available, and super::), along with the standard prelude being different under #![no_std] and macro_rules!/#[macro_use]/#[macro_export] scoping depending on mod declaration order. This is just a reality of how Rust's name resolution works. In vscode at least, rust-analyzer should warn you with a notification bar when you have a file open that isn't present in the module tree, thus is uncheckable.

You shouldn't need to use or even make pub any items in the module to have them checked, though. Mounting the code with mod is sufficient for it to be compiled and checked.

4 Likes

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.