Rust-analyzer doesn't analyse modules guarded by #[cfg(target_arch = ...)]

Note: already checked the user manual.

I have a project where some of the modules are only enabled on a certain arch, using #[cfg(target_arch = "...")] mod ... syntax. Currently rust-analyzer doesn't analyze those modules, so none of the function (hover, go to definition etc.) work. Is there a way to enable analyzing those modules? It's fine if I need to restrict analysis to only that arch as the code generated for this arch subsumes code for other archs.

I think cargo.target config option is what you are looking for: https://github.com/rust-analyzer/rust-analyzer/blob/76c1fac9c3ed9fa3f784e5cdde7dd770c9fac6c1/editors/code/package.json#L268

1 Like

Thanks!

Actually I was wrong, that didn't fix the issue. I still get no error checking & reporting for the modules behind the #[cfg(target_arch = "...")].

I was confused before because I saw some error checking, but it turns out I only get syntax errors. I don't get any type errors even when there are dozens of errors in a module.

Indeed, we didn't propagate target to checkOnSave, we only used it for our own analysis. Fixed in https://github.com/rust-analyzer/rust-analyzer/commit/a20b8d751bb59becb19c9edbb5e3f3ffe31bbcf3

1 Like

Perfect, that fixed it!

1 Like

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.