Skip to content

Commit d824871

Browse files
authored
Merge pull request #18644 from Veykril/push-nolvpzqvoqwx
Remove patch sysroot cfg-if hack
2 parents bdb2a3e + 7085328 commit d824871

File tree

2 files changed

+18
-53
lines changed

2 files changed

+18
-53
lines changed

crates/base-db/src/input.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -547,29 +547,6 @@ impl CrateGraph {
547547
None
548548
}
549549

550-
// Work around for https://github.com/rust-lang/rust-analyzer/issues/6038.
551-
// As hacky as it gets.
552-
pub fn patch_cfg_if(&mut self) -> bool {
553-
// we stupidly max by version in an attempt to have all duplicated std's depend on the same cfg_if so that deduplication still works
554-
let cfg_if =
555-
self.hacky_find_crate("cfg_if").max_by_key(|&it| self.arena[it].version.clone());
556-
let std = self.hacky_find_crate("std").next();
557-
match (cfg_if, std) {
558-
(Some(cfg_if), Some(std)) => {
559-
self.arena[cfg_if].dependencies.clear();
560-
self.arena[std]
561-
.dependencies
562-
.push(Dependency::new(CrateName::new("cfg_if").unwrap(), cfg_if));
563-
true
564-
}
565-
_ => false,
566-
}
567-
}
568-
569-
fn hacky_find_crate<'a>(&'a self, display_name: &'a str) -> impl Iterator<Item = CrateId> + 'a {
570-
self.iter().filter(move |it| self[*it].display_name.as_deref() == Some(display_name))
571-
}
572-
573550
/// Removes all crates from this crate graph except for the ones in `to_keep` and fixes up the dependencies.
574551
/// Returns a mapping from old crate ids to new crate ids.
575552
pub fn remove_crates_except(&mut self, to_keep: &[CrateId]) -> Vec<Option<CrateId>> {

crates/project-model/src/workspace.rs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -747,17 +747,14 @@ impl ProjectWorkspace {
747747
let _p = tracing::info_span!("ProjectWorkspace::to_crate_graph").entered();
748748

749749
let Self { kind, sysroot, cfg_overrides, rustc_cfg, .. } = self;
750-
let ((mut crate_graph, proc_macros), sysroot) = match kind {
751-
ProjectWorkspaceKind::Json(project) => (
752-
project_json_to_crate_graph(
753-
rustc_cfg.clone(),
754-
load,
755-
project,
756-
sysroot,
757-
extra_env,
758-
cfg_overrides,
759-
),
750+
let (crate_graph, proc_macros) = match kind {
751+
ProjectWorkspaceKind::Json(project) => project_json_to_crate_graph(
752+
rustc_cfg.clone(),
753+
load,
754+
project,
760755
sysroot,
756+
extra_env,
757+
cfg_overrides,
761758
),
762759
ProjectWorkspaceKind::Cargo {
763760
cargo,
@@ -766,20 +763,17 @@ impl ProjectWorkspace {
766763
cargo_config_extra_env: _,
767764
error: _,
768765
set_test,
769-
} => (
770-
cargo_to_crate_graph(
771-
load,
772-
rustc.as_ref().map(|a| a.as_ref()).ok(),
773-
cargo,
774-
sysroot,
775-
rustc_cfg.clone(),
776-
cfg_overrides,
777-
build_scripts,
778-
*set_test,
779-
),
766+
} => cargo_to_crate_graph(
767+
load,
768+
rustc.as_ref().map(|a| a.as_ref()).ok(),
769+
cargo,
780770
sysroot,
771+
rustc_cfg.clone(),
772+
cfg_overrides,
773+
build_scripts,
774+
*set_test,
781775
),
782-
ProjectWorkspaceKind::DetachedFile { file, cargo: cargo_script, set_test, .. } => (
776+
ProjectWorkspaceKind::DetachedFile { file, cargo: cargo_script, set_test, .. } => {
783777
if let Some((cargo, build_scripts, _)) = cargo_script {
784778
cargo_to_crate_graph(
785779
&mut |path| load(path),
@@ -800,16 +794,10 @@ impl ProjectWorkspace {
800794
cfg_overrides,
801795
*set_test,
802796
)
803-
},
804-
sysroot,
805-
),
797+
}
798+
}
806799
};
807800

808-
if matches!(sysroot.mode(), SysrootMode::Stitched(_)) && crate_graph.patch_cfg_if() {
809-
debug!("Patched std to depend on cfg-if")
810-
} else {
811-
debug!("Did not patch std to depend on cfg-if")
812-
}
813801
(crate_graph, proc_macros)
814802
}
815803

0 commit comments

Comments
 (0)