Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/project-model/src/workspace.rs41
-rw-r--r--crates/rust-analyzer/src/config.rs13
-rw-r--r--docs/user/generated_config.adoc12
-rw-r--r--editors/code/package.json10
4 files changed, 14 insertions, 62 deletions
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index 00e9c12988..6a063905ca 100644
--- a/crates/project-model/src/workspace.rs
+++ b/crates/project-model/src/workspace.rs
@@ -43,6 +43,15 @@ impl CfgOverrides {
pub fn len(&self) -> usize {
self.global.len() + self.selective.values().map(|it| it.len()).sum::<usize>()
}
+
+ fn apply(&self, cfg_options: &mut CfgOptions, name: &str) {
+ if !self.global.is_empty() {
+ cfg_options.apply_diff(self.global.clone());
+ };
+ if let Some(diff) = self.selective.get(name) {
+ cfg_options.apply_diff(diff.clone());
+ };
+ }
}
/// `PackageRoot` describes a package root folder.
@@ -999,25 +1008,13 @@ fn cargo_to_crate_graph(
let cfg_options = {
let mut cfg_options = cfg_options.clone();
- // Add test cfg for local crates
if cargo[pkg].is_local {
+ // Add test cfg for local crates
cfg_options.insert_atom("test".into());
cfg_options.insert_atom("rust_analyzer".into());
}
- if !override_cfg.global.is_empty() {
- cfg_options.apply_diff(override_cfg.global.clone());
- };
- if let Some(diff) = override_cfg.selective.get(&cargo[pkg].name) {
- // FIXME: this is sort of a hack to deal with #![cfg(not(test))] vanishing such as seen
- // in ed25519_dalek (#7243), and libcore (#9203) (although you only hit that one while
- // working on rust-lang/rust as that's the only time it appears outside sysroot).
- //
- // A more ideal solution might be to reanalyze crates based on where the cursor is and
- // figure out the set of cfgs that would have to apply to make it active.
-
- cfg_options.apply_diff(diff.clone());
- };
+ override_cfg.apply(&mut cfg_options, &cargo[pkg].name);
cfg_options
};
@@ -1153,6 +1150,7 @@ fn cargo_to_crate_graph(
&pkg_crates,
&cfg_options,
override_cfg,
+ // FIXME: Remove this once rustc switched over to rust-project.json
if rustc_workspace.workspace_root() == cargo.workspace_root() {
// the rustc workspace does not use the installed toolchain's proc-macro server
// so we need to make sure we don't use the pre compiled proc-macros there either
@@ -1250,20 +1248,7 @@ fn handle_rustc_crates(
}
let mut cfg_options = cfg_options.clone();
-
- if !override_cfg.global.is_empty() {
- cfg_options.apply_diff(override_cfg.global.clone());
- };
- if let Some(diff) = override_cfg.selective.get(&rustc_workspace[pkg].name) {
- // FIXME: this is sort of a hack to deal with #![cfg(not(test))] vanishing such as seen
- // in ed25519_dalek (#7243), and libcore (#9203) (although you only hit that one while
- // working on rust-lang/rust as that's the only time it appears outside sysroot).
- //
- // A more ideal solution might be to reanalyze crates based on where the cursor is and
- // figure out the set of cfgs that would have to apply to make it active.
-
- cfg_options.apply_diff(diff.clone());
- };
+ override_cfg.apply(&mut cfg_options, &rustc_workspace[pkg].name);
for &tgt in rustc_workspace[pkg].targets.iter() {
let kind @ TargetKind::Lib { is_proc_macro } = rustc_workspace[tgt].kind else {
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 14a4185654..0078203621 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -166,8 +166,6 @@ config_data! {
/// Set to `true` to use a subdirectory of the existing target directory or
/// set to a path relative to the workspace to use that path.
cargo_targetDir | rust_analyzerTargetDir: Option<TargetDirectory> = None,
- /// Unsets the implicit `#[cfg(test)]` for the specified crates.
- cargo_unsetTest: Vec<String> = vec!["core".to_owned()],
/// Run the check command for diagnostics on save.
checkOnSave | checkOnSave_enable: bool = true,
@@ -1604,16 +1602,7 @@ impl Config {
vec![],
)
.unwrap(),
- selective: self
- .cargo_unsetTest()
- .iter()
- .map(|it| {
- (
- it.clone(),
- CfgDiff::new(vec![], vec![CfgAtom::Flag("test".into())]).unwrap(),
- )
- })
- .collect(),
+ selective: Default::default(),
},
wrap_rustc_in_build_scripts: *self.cargo_buildScripts_useRustcWrapper(),
invocation_strategy: match self.cargo_buildScripts_invocationStrategy() {
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index af4483a2cc..14bce2083e 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -159,18 +159,6 @@ building from locking the `Cargo.lock` at the expense of duplicating build artif
Set to `true` to use a subdirectory of the existing target directory or
set to a path relative to the workspace to use that path.
--
-[[rust-analyzer.cargo.unsetTest]]rust-analyzer.cargo.unsetTest::
-+
---
-Default:
-----
-[
- "core"
-]
-----
-Unsets the implicit `#[cfg(test)]` for the specified crates.
-
---
[[rust-analyzer.checkOnSave]]rust-analyzer.checkOnSave (default: `true`)::
+
--
diff --git a/editors/code/package.json b/editors/code/package.json
index c387e72a0c..9b4875dabe 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -696,16 +696,6 @@
}
]
},
- "rust-analyzer.cargo.unsetTest": {
- "markdownDescription": "Unsets the implicit `#[cfg(test)]` for the specified crates.",
- "default": [
- "core"
- ],
- "type": "array",
- "items": {
- "type": "string"
- }
- },
"rust-analyzer.checkOnSave": {
"markdownDescription": "Run the check command for diagnostics on save.",
"default": true,