From 7a21e9302e194d5ed2a008417130c54cfa52ca24 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Oct 2020 12:34:39 +0200 Subject: Add a hacky remidy for #6038 The proper fix I think is: * move rust-lang/rust library crates to a separate workspace * when packaging rust-src component, vendor sources of external deps --- crates/base_db/src/input.rs | 23 +++++++++++++++++++++++ crates/project_model/src/lib.rs | 5 +++++ 2 files changed, 28 insertions(+) (limited to 'crates') diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index 215ac4b41..b870e2cee 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs @@ -290,6 +290,29 @@ impl CrateGraph { } false } + + // Work around for https://github.com/rust-analyzer/rust-analyzer/issues/6038. + // As hacky as it gets. + pub fn patch_cfg_if(&mut self) -> bool { + let cfg_if = self.hacky_find_crate("cfg_if"); + let std = self.hacky_find_crate("std"); + match (cfg_if, std) { + (Some(cfg_if), Some(std)) => { + self.arena.get_mut(&cfg_if).unwrap().dependencies.clear(); + self.arena + .get_mut(&std) + .unwrap() + .dependencies + .push(Dependency { crate_id: cfg_if, name: CrateName::new("cfg_if").unwrap() }); + true + } + _ => false, + } + } + + fn hacky_find_crate(&self, declaration_name: &str) -> Option { + self.iter().find(|it| self[*it].declaration_name.as_deref() == Some(declaration_name)) + } } impl ops::Index for CrateGraph { diff --git a/crates/project_model/src/lib.rs b/crates/project_model/src/lib.rs index d1e7602fc..ea95d1c77 100644 --- a/crates/project_model/src/lib.rs +++ b/crates/project_model/src/lib.rs @@ -485,6 +485,11 @@ impl ProjectWorkspace { } } } + if crate_graph.patch_cfg_if() { + log::debug!("Patched std to depend on cfg-if") + } else { + log::debug!("Did not patch std to depend on cfg-if") + } crate_graph } } -- cgit v1.2.3