Skip to content

Commit 0843d06

Browse files
authored
Merge pull request #19807 from Veykril/lw-qyynkqysuyuy
fix: Don't overwrite `RUSTUP_TOOLCHAIN` if it is already set
2 parents 6cd9c86 + 09ecc4c commit 0843d06

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

crates/project-model/src/sysroot.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ impl Sysroot {
137137
}
138138

139139
let mut cmd = toolchain::command(tool.prefer_proxy(), current_dir, envs);
140-
cmd.env("RUSTUP_TOOLCHAIN", AsRef::<std::path::Path>::as_ref(root));
140+
if !envs.contains_key("RUSTUP_TOOLCHAIN")
141+
&& std::env::var_os("RUSTUP_TOOLCHAIN").is_none()
142+
{
143+
cmd.env("RUSTUP_TOOLCHAIN", AsRef::<std::path::Path>::as_ref(root));
144+
}
145+
141146
cmd
142147
}
143148
_ => toolchain::command(tool.path(), current_dir, envs),

crates/rust-analyzer/src/flycheck.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,11 @@ impl FlycheckActor {
470470
let mut cmd =
471471
toolchain::command(Tool::Cargo.path(), &*self.root, &options.extra_env);
472472
if let Some(sysroot_root) = &self.sysroot_root {
473-
cmd.env("RUSTUP_TOOLCHAIN", AsRef::<std::path::Path>::as_ref(sysroot_root));
473+
if !options.extra_env.contains_key("RUSTUP_TOOLCHAIN")
474+
&& std::env::var_os("RUSTUP_TOOLCHAIN").is_none()
475+
{
476+
cmd.env("RUSTUP_TOOLCHAIN", AsRef::<std::path::Path>::as_ref(sysroot_root));
477+
}
474478
}
475479
cmd.arg(command);
476480

crates/rust-analyzer/src/reload.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,10 @@ impl GlobalState {
659659
.chain(
660660
ws.sysroot
661661
.root()
662+
.filter(|_| {
663+
!self.config.extra_env(None).contains_key("RUSTUP_TOOLCHAIN")
664+
&& std::env::var_os("RUSTUP_TOOLCHAIN").is_none()
665+
})
662666
.map(|it| ("RUSTUP_TOOLCHAIN".to_owned(), Some(it.to_string()))),
663667
)
664668
.collect(),

0 commit comments

Comments
 (0)