Skip to content

Commit

Permalink
Merge pull request #18644 from Veykril/push-nolvpzqvoqwx
Browse files Browse the repository at this point in the history
Remove patch sysroot cfg-if hack
  • Loading branch information
Veykril authored Dec 9, 2024
2 parents bdb2a3e + 7085328 commit d824871
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 53 deletions.
23 changes: 0 additions & 23 deletions crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,29 +547,6 @@ impl CrateGraph {
None
}

// Work around for https://github.com/rust-lang/rust-analyzer/issues/6038.
// As hacky as it gets.
pub fn patch_cfg_if(&mut self) -> bool {
// 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
let cfg_if =
self.hacky_find_crate("cfg_if").max_by_key(|&it| self.arena[it].version.clone());
let std = self.hacky_find_crate("std").next();
match (cfg_if, std) {
(Some(cfg_if), Some(std)) => {
self.arena[cfg_if].dependencies.clear();
self.arena[std]
.dependencies
.push(Dependency::new(CrateName::new("cfg_if").unwrap(), cfg_if));
true
}
_ => false,
}
}

fn hacky_find_crate<'a>(&'a self, display_name: &'a str) -> impl Iterator<Item = CrateId> + 'a {
self.iter().filter(move |it| self[*it].display_name.as_deref() == Some(display_name))
}

/// Removes all crates from this crate graph except for the ones in `to_keep` and fixes up the dependencies.
/// Returns a mapping from old crate ids to new crate ids.
pub fn remove_crates_except(&mut self, to_keep: &[CrateId]) -> Vec<Option<CrateId>> {
Expand Down
48 changes: 18 additions & 30 deletions crates/project-model/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,17 +747,14 @@ impl ProjectWorkspace {
let _p = tracing::info_span!("ProjectWorkspace::to_crate_graph").entered();

let Self { kind, sysroot, cfg_overrides, rustc_cfg, .. } = self;
let ((mut crate_graph, proc_macros), sysroot) = match kind {
ProjectWorkspaceKind::Json(project) => (
project_json_to_crate_graph(
rustc_cfg.clone(),
load,
project,
sysroot,
extra_env,
cfg_overrides,
),
let (crate_graph, proc_macros) = match kind {
ProjectWorkspaceKind::Json(project) => project_json_to_crate_graph(
rustc_cfg.clone(),
load,
project,
sysroot,
extra_env,
cfg_overrides,
),
ProjectWorkspaceKind::Cargo {
cargo,
Expand All @@ -766,20 +763,17 @@ impl ProjectWorkspace {
cargo_config_extra_env: _,
error: _,
set_test,
} => (
cargo_to_crate_graph(
load,
rustc.as_ref().map(|a| a.as_ref()).ok(),
cargo,
sysroot,
rustc_cfg.clone(),
cfg_overrides,
build_scripts,
*set_test,
),
} => cargo_to_crate_graph(
load,
rustc.as_ref().map(|a| a.as_ref()).ok(),
cargo,
sysroot,
rustc_cfg.clone(),
cfg_overrides,
build_scripts,
*set_test,
),
ProjectWorkspaceKind::DetachedFile { file, cargo: cargo_script, set_test, .. } => (
ProjectWorkspaceKind::DetachedFile { file, cargo: cargo_script, set_test, .. } => {
if let Some((cargo, build_scripts, _)) = cargo_script {
cargo_to_crate_graph(
&mut |path| load(path),
Expand All @@ -800,16 +794,10 @@ impl ProjectWorkspace {
cfg_overrides,
*set_test,
)
},
sysroot,
),
}
}
};

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

Expand Down

0 comments on commit d824871

Please sign in to comment.