From b9f76287c299719ae91c0cdf6a24da3ebf065ffc Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 16 Feb 2025 10:51:58 +0100 Subject: [PATCH] Set `RUSTUP_TOOLCHAIN` when loading sysroot workspace --- crates/project-model/src/cargo_workspace.rs | 3 +++ crates/project-model/src/sysroot.rs | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs index e4a611346205..b5f4e43a115d 100644 --- a/crates/project-model/src/cargo_workspace.rs +++ b/crates/project-model/src/cargo_workspace.rs @@ -277,6 +277,9 @@ impl CargoWorkspace { /// Fetches the metadata for the given `cargo_toml` manifest. /// A successful result may contain another metadata error if the initial fetching failed but /// the `--no-deps` retry succeeded. + /// + /// The sysroot is used to set the `RUSTUP_TOOLCHAIN` env var when invoking cargo + /// to ensure that the rustup proxy uses the correct toolchain. pub fn fetch_metadata( cargo_toml: &ManifestPath, current_dir: &AbsPath, diff --git a/crates/project-model/src/sysroot.rs b/crates/project-model/src/sysroot.rs index 510c18dd147e..544ba43ba66f 100644 --- a/crates/project-model/src/sysroot.rs +++ b/crates/project-model/src/sysroot.rs @@ -247,7 +247,7 @@ impl Sysroot { let library_manifest = ManifestPath::try_from(src_root.join("Cargo.toml")).unwrap(); if fs::metadata(&library_manifest).is_ok() { if let Some(loaded) = - Self::load_library_via_cargo(library_manifest, src_root, cargo_config) + self.load_library_via_cargo(library_manifest, src_root, cargo_config) { return Some(loaded); } @@ -326,6 +326,7 @@ impl Sysroot { } fn load_library_via_cargo( + &self, library_manifest: ManifestPath, rust_lib_src_dir: &AbsPathBuf, cargo_config: &CargoMetadataConfig, @@ -342,7 +343,7 @@ impl Sysroot { &library_manifest, rust_lib_src_dir, &cargo_config, - &Sysroot::empty(), + self, // Make sure we never attempt to write to the sysroot true, &|_| (),