Open nipunn1313 opened 1 year ago
Rust-analyzer can only analyze one cfg()
configuration at a time. Any code inside an inactive #[cfg]
will have most ide functionality like autocompletion, rust-analyzer native diagnostics and inlay hints disabled. We have a warning to prevent confusion about why ide functionality doesn't work in these blocks.
cool - that makes sense. It's a bit of a bummer, but an understandable one. Out of curiosity, what does rust-analyzer use as a default cfg?
I believe it uses the default of rustc for the respective target + all features enabled when the root is compiled with --all-features
+ cfg(test)
(unless the rust-analyzer.cargo.unsetTest
config contains the name of the respective crate).
Is there an easy way to enable --all-features
+ cfg(test)
+ cfg(doc)
?
I tried setting --cfg doc
in cargo.extraEnv
but it seemed to disable some of the other cfgs (like proc macro)
doc
feel like a special language-endorsed cfg (like test
) and I wonder if there's a discussion/argument for including it in the default.
I'm also looking for a way to enable all features, since rust-analyzer.cargo.allFeatures
apparently does not exist anymore (as suggested here).
You can set rust-analyzer.cargo.features
to "all"
rather than an array of features to enable all features.
When I set "rust-analyzer.cargo.features": ["all"]
in VS Code I get the following error:
[ERROR rust_analyzer::main_loop] FetchWorkspaceError:
rust-analyzer failed to load workspace: Failed to load the project at ...snip.../rust/Cargo.toml: Failed to read Cargo metadata from Cargo.toml file ...snip.../rust/Cargo.toml, Some(Version { major: 1, minor: 71, patch: 0 }): Failed to run `cd "...snip.../rust" && "cargo" "metadata" "--format-version" "1" "--features" "all" "--manifest-path" "...snip.../rust/Cargo.toml" "--filter-platform" "aarch64-apple-darwin"`: `cargo metadata` exited with an error: error: none of the selected packages contains these features: all
If I set it to a specific feature it seems to work fine. Not sure what I'm missing.
@nine9ths Try "rust-analyzer.cargo.features": "all"
.
Perhaps there could be something similar to #[allow(dead_code)]
for circumstances such as these? It's really nice to have no noise from linters in the editor.
The inactive-code check appears to false positive (IMO) on
#[cfg(doc)]
.Sample code
One could potentially argue that this is behaving-as-designed, since it's analyzing the code, but not the docs - but I found it a bit un-useful.
Some possible proposed solutions
cfg(doc)
code blocks in the inactive-code analyzer.