Remove rustc core test cfg hacks

This commit is contained in:
Lukas Wirth 2024-03-01 13:49:22 +01:00
parent 062e1b9b81
commit 2e54c0af40
4 changed files with 14 additions and 62 deletions

View file

@ -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 {

View file

@ -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() {

View file

@ -158,18 +158,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`)::
+

View file

@ -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,