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 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'crates/base_db') 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 { -- cgit v1.2.3