6294: Add a hacky remidy for #6038 r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-10-20 10:36:28 +00:00 committed by GitHub
commit be762ccccd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View file

@ -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<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 @@ 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
}
}