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
This commit is contained in:
Aleksey Kladov 2020-10-20 12:34:39 +02:00
parent 378dd90bab
commit 7a21e9302e
2 changed files with 28 additions and 0 deletions

View File

@ -290,6 +290,29 @@ fn dfs_find(&self, target: CrateId, from: CrateId, visited: &mut FxHashSet<Crate
}
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<CrateId> {
self.iter().find(|it| self[*it].declaration_name.as_deref() == Some(declaration_name))
}
}
impl ops::Index<CrateId> for CrateGraph {

View File

@ -485,6 +485,11 @@ pub fn to_crate_graph(
}
}
}
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
}
}