mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
Remove patch sysroot cfg-if hack
This commit is contained in:
parent
1c3043bc8c
commit
7085328185
2 changed files with 18 additions and 53 deletions
|
@ -547,29 +547,6 @@ impl CrateGraph {
|
|||
None
|
||||
}
|
||||
|
||||
// Work around for https://github.com/rust-lang/rust-analyzer/issues/6038.
|
||||
// As hacky as it gets.
|
||||
pub fn patch_cfg_if(&mut self) -> bool {
|
||||
// we stupidly max by version in an attempt to have all duplicated std's depend on the same cfg_if so that deduplication still works
|
||||
let cfg_if =
|
||||
self.hacky_find_crate("cfg_if").max_by_key(|&it| self.arena[it].version.clone());
|
||||
let std = self.hacky_find_crate("std").next();
|
||||
match (cfg_if, std) {
|
||||
(Some(cfg_if), Some(std)) => {
|
||||
self.arena[cfg_if].dependencies.clear();
|
||||
self.arena[std]
|
||||
.dependencies
|
||||
.push(Dependency::new(CrateName::new("cfg_if").unwrap(), cfg_if));
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn hacky_find_crate<'a>(&'a self, display_name: &'a str) -> impl Iterator<Item = CrateId> + 'a {
|
||||
self.iter().filter(move |it| self[*it].display_name.as_deref() == Some(display_name))
|
||||
}
|
||||
|
||||
/// Removes all crates from this crate graph except for the ones in `to_keep` and fixes up the dependencies.
|
||||
/// Returns a mapping from old crate ids to new crate ids.
|
||||
pub fn remove_crates_except(&mut self, to_keep: &[CrateId]) -> Vec<Option<CrateId>> {
|
||||
|
|
|
@ -747,17 +747,14 @@ impl ProjectWorkspace {
|
|||
let _p = tracing::info_span!("ProjectWorkspace::to_crate_graph").entered();
|
||||
|
||||
let Self { kind, sysroot, cfg_overrides, rustc_cfg, .. } = self;
|
||||
let ((mut crate_graph, proc_macros), sysroot) = match kind {
|
||||
ProjectWorkspaceKind::Json(project) => (
|
||||
project_json_to_crate_graph(
|
||||
rustc_cfg.clone(),
|
||||
load,
|
||||
project,
|
||||
sysroot,
|
||||
extra_env,
|
||||
cfg_overrides,
|
||||
),
|
||||
let (crate_graph, proc_macros) = match kind {
|
||||
ProjectWorkspaceKind::Json(project) => project_json_to_crate_graph(
|
||||
rustc_cfg.clone(),
|
||||
load,
|
||||
project,
|
||||
sysroot,
|
||||
extra_env,
|
||||
cfg_overrides,
|
||||
),
|
||||
ProjectWorkspaceKind::Cargo {
|
||||
cargo,
|
||||
|
@ -766,20 +763,17 @@ impl ProjectWorkspace {
|
|||
cargo_config_extra_env: _,
|
||||
error: _,
|
||||
set_test,
|
||||
} => (
|
||||
cargo_to_crate_graph(
|
||||
load,
|
||||
rustc.as_ref().map(|a| a.as_ref()).ok(),
|
||||
cargo,
|
||||
sysroot,
|
||||
rustc_cfg.clone(),
|
||||
cfg_overrides,
|
||||
build_scripts,
|
||||
*set_test,
|
||||
),
|
||||
} => cargo_to_crate_graph(
|
||||
load,
|
||||
rustc.as_ref().map(|a| a.as_ref()).ok(),
|
||||
cargo,
|
||||
sysroot,
|
||||
rustc_cfg.clone(),
|
||||
cfg_overrides,
|
||||
build_scripts,
|
||||
*set_test,
|
||||
),
|
||||
ProjectWorkspaceKind::DetachedFile { file, cargo: cargo_script, set_test, .. } => (
|
||||
ProjectWorkspaceKind::DetachedFile { file, cargo: cargo_script, set_test, .. } => {
|
||||
if let Some((cargo, build_scripts, _)) = cargo_script {
|
||||
cargo_to_crate_graph(
|
||||
&mut |path| load(path),
|
||||
|
@ -800,16 +794,10 @@ impl ProjectWorkspace {
|
|||
cfg_overrides,
|
||||
*set_test,
|
||||
)
|
||||
},
|
||||
sysroot,
|
||||
),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if matches!(sysroot.mode(), SysrootMode::Stitched(_)) && crate_graph.patch_cfg_if() {
|
||||
debug!("Patched std to depend on cfg-if")
|
||||
} else {
|
||||
debug!("Did not patch std to depend on cfg-if")
|
||||
}
|
||||
(crate_graph, proc_macros)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue