Skip to content

Commit be762cc

Browse files
bors[bot]matklad
andauthored
Merge #6294
6294: Add a hacky remidy for #6038 r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 4c00bde + 7a21e93 commit be762cc

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

crates/base_db/src/input.rs

+23
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,29 @@ impl CrateGraph {
290290
}
291291
false
292292
}
293+
294+
// Work around for https://github.com/rust-analyzer/rust-analyzer/issues/6038.
295+
// As hacky as it gets.
296+
pub fn patch_cfg_if(&mut self) -> bool {
297+
let cfg_if = self.hacky_find_crate("cfg_if");
298+
let std = self.hacky_find_crate("std");
299+
match (cfg_if, std) {
300+
(Some(cfg_if), Some(std)) => {
301+
self.arena.get_mut(&cfg_if).unwrap().dependencies.clear();
302+
self.arena
303+
.get_mut(&std)
304+
.unwrap()
305+
.dependencies
306+
.push(Dependency { crate_id: cfg_if, name: CrateName::new("cfg_if").unwrap() });
307+
true
308+
}
309+
_ => false,
310+
}
311+
}
312+
313+
fn hacky_find_crate(&self, declaration_name: &str) -> Option<CrateId> {
314+
self.iter().find(|it| self[*it].declaration_name.as_deref() == Some(declaration_name))
315+
}
293316
}
294317

295318
impl ops::Index<CrateId> for CrateGraph {

crates/project_model/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ impl ProjectWorkspace {
485485
}
486486
}
487487
}
488+
if crate_graph.patch_cfg_if() {
489+
log::debug!("Patched std to depend on cfg-if")
490+
} else {
491+
log::debug!("Did not patch std to depend on cfg-if")
492+
}
488493
crate_graph
489494
}
490495
}

0 commit comments

Comments
 (0)