diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index 215ac4b41dd..b870e2ceedf 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 d1e7602fc51..ea95d1c7716 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 } }