Skip to content

Commit a247418

Browse files
committed
Remove rustc workspace hacks
1 parent 9efa23c commit a247418

File tree

4 files changed

+18
-64
lines changed

4 files changed

+18
-64
lines changed

crates/project-model/src/workspace.rs

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ impl CfgOverrides {
4242
pub fn len(&self) -> usize {
4343
self.global.len() + self.selective.values().map(|it| it.len()).sum::<usize>()
4444
}
45+
46+
fn apply(&self, cfg_options: &mut CfgOptions, name: &str) {
47+
if !self.global.is_empty() {
48+
cfg_options.apply_diff(self.global.clone());
49+
};
50+
if let Some(diff) = self.selective.get(name) {
51+
cfg_options.apply_diff(diff.clone());
52+
};
53+
}
4554
}
4655

4756
/// `PackageRoot` describes a package root folder.
@@ -983,25 +992,13 @@ fn cargo_to_crate_graph(
983992
let cfg_options = {
984993
let mut cfg_options = cfg_options.clone();
985994

986-
// Add test cfg for local crates
987995
if cargo[pkg].is_local {
996+
// Add test cfg for local crates
988997
cfg_options.insert_atom("test".into());
989998
cfg_options.insert_atom("rust_analyzer".into());
990999
}
9911000

992-
if !override_cfg.global.is_empty() {
993-
cfg_options.apply_diff(override_cfg.global.clone());
994-
};
995-
if let Some(diff) = override_cfg.selective.get(&cargo[pkg].name) {
996-
// FIXME: this is sort of a hack to deal with #![cfg(not(test))] vanishing such as seen
997-
// in ed25519_dalek (#7243), and libcore (#9203) (although you only hit that one while
998-
// working on rust-lang/rust as that's the only time it appears outside sysroot).
999-
//
1000-
// A more ideal solution might be to reanalyze crates based on where the cursor is and
1001-
// figure out the set of cfgs that would have to apply to make it active.
1002-
1003-
cfg_options.apply_diff(diff.clone());
1004-
};
1001+
override_cfg.apply(&mut cfg_options, &cargo[pkg].name);
10051002
cfg_options
10061003
};
10071004

@@ -1115,13 +1112,7 @@ fn cargo_to_crate_graph(
11151112
&pkg_crates,
11161113
&cfg_options,
11171114
override_cfg,
1118-
if rustc_workspace.workspace_root() == cargo.workspace_root() {
1119-
// the rustc workspace does not use the installed toolchain's proc-macro server
1120-
// so we need to make sure we don't use the pre compiled proc-macros there either
1121-
build_scripts
1122-
} else {
1123-
rustc_build_scripts
1124-
},
1115+
rustc_build_scripts,
11251116
);
11261117
}
11271118
}
@@ -1212,20 +1203,7 @@ fn handle_rustc_crates(
12121203
}
12131204

12141205
let mut cfg_options = cfg_options.clone();
1215-
1216-
if !override_cfg.global.is_empty() {
1217-
cfg_options.apply_diff(override_cfg.global.clone());
1218-
};
1219-
if let Some(diff) = override_cfg.selective.get(&rustc_workspace[pkg].name) {
1220-
// FIXME: this is sort of a hack to deal with #![cfg(not(test))] vanishing such as seen
1221-
// in ed25519_dalek (#7243), and libcore (#9203) (although you only hit that one while
1222-
// working on rust-lang/rust as that's the only time it appears outside sysroot).
1223-
//
1224-
// A more ideal solution might be to reanalyze crates based on where the cursor is and
1225-
// figure out the set of cfgs that would have to apply to make it active.
1226-
1227-
cfg_options.apply_diff(diff.clone());
1228-
};
1206+
override_cfg.apply(&mut cfg_options, &rustc_workspace[pkg].name);
12291207

12301208
for &tgt in rustc_workspace[pkg].targets.iter() {
12311209
let kind @ TargetKind::Lib { is_proc_macro } = rustc_workspace[tgt].kind else {

crates/rust-analyzer/src/config.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ config_data! {
152152
// FIXME(@poliorcetics): move to multiple targets here too, but this will need more work
153153
// than `checkOnSave_target`
154154
cargo_target: Option<String> = "null",
155-
/// Unsets the implicit `#[cfg(test)]` for the specified crates.
156-
cargo_unsetTest: Vec<String> = "[\"core\"]",
157155

158156
/// Run the check command for diagnostics on save.
159157
checkOnSave | checkOnSave_enable: bool = "true",
@@ -1292,18 +1290,11 @@ impl Config {
12921290
.collect(),
12931291
vec![],
12941292
)
1295-
.unwrap(),
1296-
selective: self
1297-
.data
1298-
.cargo_unsetTest
1299-
.iter()
1300-
.map(|it| {
1301-
(
1302-
it.clone(),
1303-
CfgDiff::new(vec![], vec![CfgAtom::Flag("test".into())]).unwrap(),
1304-
)
1305-
})
1306-
.collect(),
1293+
.unwrap_or_else(|| {
1294+
tracing::error!("`cargo.cfgs` config contains duplicate keys");
1295+
Default::default()
1296+
}),
1297+
selective: Default::default(),
13071298
},
13081299
wrap_rustc_in_build_scripts: self.data.cargo_buildScripts_useRustcWrapper,
13091300
invocation_strategy: match self.data.cargo_buildScripts_invocationStrategy {

docs/user/generated_config.adoc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ This option does not take effect until rust-analyzer is restarted.
144144
--
145145
Compilation target override (target triple).
146146
--
147-
[[rust-analyzer.cargo.unsetTest]]rust-analyzer.cargo.unsetTest (default: `["core"]`)::
148-
+
149-
--
150-
Unsets the implicit `#[cfg(test)]` for the specified crates.
151-
--
152147
[[rust-analyzer.checkOnSave]]rust-analyzer.checkOnSave (default: `true`)::
153148
+
154149
--

editors/code/package.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -671,16 +671,6 @@
671671
"string"
672672
]
673673
},
674-
"rust-analyzer.cargo.unsetTest": {
675-
"markdownDescription": "Unsets the implicit `#[cfg(test)]` for the specified crates.",
676-
"default": [
677-
"core"
678-
],
679-
"type": "array",
680-
"items": {
681-
"type": "string"
682-
}
683-
},
684674
"rust-analyzer.checkOnSave": {
685675
"markdownDescription": "Run the check command for diagnostics on save.",
686676
"default": true,

0 commit comments

Comments
 (0)