Hi. I'm experiencing (what I assume to be) a bug with rust-analyzer, but my uses case is pretty unique so I wouldn't be surprised if this is something that isn't supported.
I'm using a declarative macro debug_release_modules
in multiple places throughout my project to toggle what code gets compiled.
I'm using VS Code with the latest rust-analyzer version (v0.2.654).
I've managed to reduce my problem to this minimal example with three files.
// main.rs
macro_rules! debug_release_modules {
() => {
#[cfg(debug_assertions)]
pub mod debug;
#[cfg(debug_assertions)]
pub use debug::*;
#[cfg(not(debug_assertions))]
pub mod release;
#[cfg(not(debug_assertions))]
pub use release::*;
};
}
debug_release_modules!();
fn main() {
println!("{}", MODE);
}
// debug.rs
pub const MODE: &str = "DEBUG";
const VALUE: i32 = 15.7;
// release.rs
pub const MODE: &str = "RELEASE";
const VALUE: i32 = 15.7;
When load my project with rust-analyzer with it's default settings, this works fine. It correctly identifies the error with assigning a float to the VALUE
constant in the debug.rs
file.
If I edit the extension settings like so:
"rust-analyzer.runnables.cargoExtraArgs": [
"--release"
],
"rust-analyzer.checkOnSave.extraArgs": [
"--release"
],
Then it now highlights the error in release.rs
and the error in debug.rs
is gone. This is the behavior I expect.
However, in both cases rust-analyzer gives me an error on the release.rs
file saying:
file not included in module tree (unlinked-file)
I would expect this error to be present in release.rs
when using debug compilation. But it doesn't switch to complaining that debug.rs
isn't included with release compilation.
This isn't negatively affecting me too much, but it does add a lot of noise to the 'problems' pane in VS Code.
Should I file this as a bug in rust-analyzers repo, or is doing something like this with macros and module inclusion never going to work smoothly?