我设置了vscode与锈蚀分析器插件,它在大多数情况下工作。我刚刚添加了一个可选的特性,但是我不能让vscode/锈蚀分析器解析代码,相反,它总是显示:
code is inactive due to #[cfg] directives: std is disabled rust-analyzer (inactive-code)Cargo.toml:
[dependencies]
rand = {version = "0.8.5", default-features = false}
[features]
std = ["rand/std"]main.rs:
#[cfg(std)]
use rand;
fn main() {}我的设置文件有以下几行:
"rust-analyzer.cargo.features": "all",
"rust-analyzer.checkOnSave.features": "all"我认为这可能与同时使用VSCode工作区和货物工作区有关,但将其简化为存根货运项目也会出现同样的问题。
最后,我遵循了这个问题中的建议(没有运行并启用RA_LOGS的其他插件),但是输出似乎显示了我期望的--all-features:How to activate an optional dependency?命令
[INFO flycheck] restart flycheck "cargo" "check" "--workspace" "--message-format=json" "--manifest-path" "$HOME/workspace/stackoverflow/Cargo.toml" "--all-targets" "--all-features"知道我还能查些什么吗?
发布于 2022-06-07 17:37:08
对不起,我意识到我用错了cfg的表格。它应该是:
#[cfg(feature = "std")]在我的真实代码中,我有一个效果与#[cfg(features = "std")]相同的错误
https://stackoverflow.com/questions/72535183
复制相似问题