Skip to content

Commit

Permalink
Add a hacky remidy for rust-lang#6038
Browse files Browse the repository at this point in the history
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
  • Loading branch information
matklad authored and bnjjj committed Oct 20, 2020
1 parent 824b89d commit d5ae193
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crates/base_db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions crates/project_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit d5ae193

Please sign in to comment.