From 708532818593c1d526da5c68182f46f6624b084c Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 9 Dec 2024 11:42:51 +0100 Subject: [PATCH] Remove patch sysroot cfg-if hack --- crates/base-db/src/input.rs | 23 ------------- crates/project-model/src/workspace.rs | 48 ++++++++++----------------- 2 files changed, 18 insertions(+), 53 deletions(-) diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs index 57522d6932..e86944eeb3 100644 --- a/crates/base-db/src/input.rs +++ b/crates/base-db/src/input.rs @@ -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 + '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> { diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs index f5ba71fcd0..988eff9be4 100644 --- a/crates/project-model/src/workspace.rs +++ b/crates/project-model/src/workspace.rs @@ -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) }