From d53fccff2f809f19b87d802ef735f5096644175a Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 28 Apr 2026 21:52:45 +0200 Subject: [PATCH 1/8] feat(config): add `Cfg` field to force-disable auto-installation --- src/cli/proxy_mode.rs | 2 +- src/cli/rustup_mode.rs | 4 ++-- src/cli/self_update.rs | 2 +- src/cli/setup_mode.rs | 2 +- src/config.rs | 14 ++++++++++++++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/cli/proxy_mode.rs b/src/cli/proxy_mode.rs index cb3df2b88f..0e480e920f 100644 --- a/src/cli/proxy_mode.rs +++ b/src/cli/proxy_mode.rs @@ -32,7 +32,7 @@ pub async fn main(arg0: &str, current_dir: PathBuf, process: &Process) -> Result .skip(1 + toolchain.is_some() as usize) .collect(); - let cfg = Cfg::from_env(current_dir, false, process)?; + let cfg = Cfg::from_env(current_dir, false, true, process)?; let (toolchain, source) = cfg .local_toolchain(match toolchain { Some(name) => Some(( diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index aebd45e349..7069910e9d 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -631,7 +631,7 @@ pub async fn main( update_console_filter(process, &console_filter, matches.quiet, matches.verbose); - let cfg = &mut Cfg::from_env(current_dir, matches.quiet, process)?; + let cfg = &mut Cfg::from_env(current_dir, matches.quiet, true, process)?; cfg.toolchain_override = matches.plus_toolchain; let Some(subcmd) = matches.subcmd else { @@ -1974,7 +1974,7 @@ fn output_completion_script( async fn display_version(current_dir: PathBuf, process: &Process) -> Result<()> { info!("This is the version for the rustup toolchain manager, not the rustc compiler."); - let mut cfg = Cfg::from_env(current_dir, true, process)?; + let mut cfg = Cfg::from_env(current_dir, true, true, process)?; cfg.toolchain_override = cfg .process .args() diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index 7b47c3fcde..5e3af678b6 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -1462,7 +1462,7 @@ mod tests { home.apply(&mut vars); let tp = TestProcess::with_vars(vars); let mut cfg = - Cfg::from_env(tp.process.current_dir().unwrap(), false, &tp.process).unwrap(); + Cfg::from_env(tp.process.current_dir().unwrap(), false, true, &tp.process).unwrap(); let opts = InstallOpts { default_host_tuple: None, diff --git a/src/cli/setup_mode.rs b/src/cli/setup_mode.rs index 178b1e7ee4..f8a7838874 100644 --- a/src/cli/setup_mode.rs +++ b/src/cli/setup_mode.rs @@ -130,6 +130,6 @@ pub async fn main( targets: &target.iter().map(|s| &**s).collect::>(), }; - let mut cfg = Cfg::from_env(current_dir, quiet, process)?; + let mut cfg = Cfg::from_env(current_dir, quiet, true, process)?; self_update::install(no_prompt, opts, &mut cfg).await } diff --git a/src/config.rs b/src/config.rs index 9eff930a98..b4022af567 100644 --- a/src/config.rs +++ b/src/config.rs @@ -246,12 +246,19 @@ pub(crate) struct Cfg<'a> { pub quiet: bool, pub current_dir: PathBuf, pub process: &'a Process, + + /// If this flag is set to `false`, it can stop `rustup` from automatically installing the + /// active toolchain in certain undesired cases, such as under `rustup component` and `rustup + /// target` subcommands. This effect has higher precedence than the `RUSTUP_AUTO_INSTALL` + /// environment variable and the `rustup set auto-install` setting. + pub allow_auto_install: bool, } impl<'a> Cfg<'a> { pub(crate) fn from_env( current_dir: PathBuf, quiet: bool, + allow_auto_install: bool, process: &'a Process, ) -> Result { // Set up the rustup home directory @@ -316,6 +323,7 @@ impl<'a> Cfg<'a> { quiet, current_dir, process, + allow_auto_install, }; // Run some basic checks against the constructed configuration @@ -372,6 +380,10 @@ impl<'a> Cfg<'a> { } pub(crate) fn should_auto_install(&self) -> Result { + if !self.allow_auto_install { + return Ok(false); + } + if let Ok(mode) = self.process.var("RUSTUP_AUTO_INSTALL") { Ok(mode != "0") } else { @@ -958,6 +970,7 @@ impl Debug for Cfg<'_> { dist_root_url, quiet, current_dir, + allow_auto_install, process: _, } = self; @@ -975,6 +988,7 @@ impl Debug for Cfg<'_> { .field("dist_root_url", dist_root_url) .field("quiet", quiet) .field("current_dir", current_dir) + .field("allow_auto_install", allow_auto_install) .finish() } } From bc01f23b36e465f0361e791cd7117b2ac5c3c3ad Mon Sep 17 00:00:00 2001 From: rami3l Date: Mon, 4 May 2026 22:06:56 +0200 Subject: [PATCH 2/8] fix(cli/setup-mode)!: skip auto-installation in `rustup-init` --- src/cli/setup_mode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/setup_mode.rs b/src/cli/setup_mode.rs index f8a7838874..f43e9086ae 100644 --- a/src/cli/setup_mode.rs +++ b/src/cli/setup_mode.rs @@ -130,6 +130,6 @@ pub async fn main( targets: &target.iter().map(|s| &**s).collect::>(), }; - let mut cfg = Cfg::from_env(current_dir, quiet, true, process)?; + let mut cfg = Cfg::from_env(current_dir, quiet, false, process)?; self_update::install(no_prompt, opts, &mut cfg).await } From b5484df2e7ad4795c40c0c252d82d174b48e4e07 Mon Sep 17 00:00:00 2001 From: rami3l Date: Wed, 6 May 2026 22:04:27 +0200 Subject: [PATCH 3/8] refactor(cli/rustup-mode): refine usage of `stdout` term and locks in `show()` --- src/cli/rustup_mode.rs | 116 ++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 64 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 7069910e9d..7b2c598498 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -1108,20 +1108,17 @@ async fn which( async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result { common::warn_if_host_is_emulated(cfg.process); + let mut t = cfg.process.stdout(); + // Print host tuple - { - let t = cfg.process.stdout(); - let mut t = t.lock(); - writeln!( - t, - "{HEADER}Default host: {HEADER:#}{}", - cfg.default_host_tuple()? - )?; - } + writeln!( + t.lock(), + "{HEADER}Default host: {HEADER:#}{}", + cfg.default_host_tuple()? + )?; // Print rustup home directory { - let t = cfg.process.stdout(); let mut t = t.lock(); writeln!( t, @@ -1162,74 +1159,65 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result { }; // show installed toolchains - { - let mut t = cfg.process.stdout(); - - print_header(&mut t, "installed toolchains")?; - - let default_toolchain_name = cfg.get_default()?; - let last_index = installed_toolchains.len().wrapping_sub(1); - for (n, toolchain_name) in installed_toolchains.into_iter().enumerate() { - let is_default_toolchain = default_toolchain_name.as_ref() == Some(&toolchain_name); - let is_active_toolchain = active_toolchain_name == Some(&toolchain_name); + print_header(&mut t, "installed toolchains")?; + + let default_toolchain_name = cfg.get_default()?; + let last_index = installed_toolchains.len().wrapping_sub(1); + for (n, toolchain_name) in installed_toolchains.into_iter().enumerate() { + let is_default_toolchain = default_toolchain_name.as_ref() == Some(&toolchain_name); + let is_active_toolchain = active_toolchain_name == Some(&toolchain_name); + + let status_str = match (is_active_toolchain, is_default_toolchain) { + (true, true) => " (active, default)", + (true, false) => " (active)", + (false, true) => " (default)", + (false, false) => "", + }; - let status_str = match (is_active_toolchain, is_default_toolchain) { - (true, true) => " (active, default)", - (true, false) => " (active)", - (false, true) => " (default)", - (false, false) => "", - }; + let mut t = t.lock(); - writeln!(t.lock(), "{toolchain_name}{CONTEXT}{status_str}{CONTEXT:#}")?; + writeln!(t, "{toolchain_name}{CONTEXT}{status_str}{CONTEXT:#}")?; - if verbose { - let toolchain = Toolchain::new(cfg, toolchain_name.into())?; - writeln!( - cfg.process.stdout().lock(), - " {}\n path: {}", - toolchain.rustc_version(), - toolchain.path().display() - )?; - if n != last_index { - writeln!(cfg.process.stdout().lock())?; - } + if verbose { + let toolchain = Toolchain::new(cfg, toolchain_name.into())?; + writeln!( + t, + " {}\n path: {}", + toolchain.rustc_version(), + toolchain.path().display() + )?; + if n != last_index { + writeln!(t)?; } } } // show active toolchain - { - let mut t = cfg.process.stdout(); - - writeln!(t.lock())?; + writeln!(t.lock())?; - print_header(&mut t, "active toolchain")?; + print_header(&mut t, "active toolchain")?; - match active_toolchain_and_source { - Some((active_toolchain_name, active_source)) => { - let active_toolchain = Toolchain::with_source( - cfg, - active_toolchain_name.clone().into(), - &active_source, - )?; - writeln!(t.lock(), "name: {}", active_toolchain.name())?; - writeln!(t.lock(), "active because: {}", active_source.to_reason())?; - if verbose { - writeln!(t.lock(), "compiler: {}", active_toolchain.rustc_version())?; - writeln!(t.lock(), "path: {}", active_toolchain.path().display())?; - } + match active_toolchain_and_source { + Some((active_toolchain_name, active_source)) => { + let active_toolchain = + Toolchain::with_source(cfg, active_toolchain_name.clone().into(), &active_source)?; + writeln!(t.lock(), "name: {}", active_toolchain.name())?; + writeln!(t.lock(), "active because: {}", active_source.to_reason())?; + if verbose { + writeln!(t.lock(), "compiler: {}", active_toolchain.rustc_version())?; + writeln!(t.lock(), "path: {}", active_toolchain.path().display())?; + } - // show installed targets for the active toolchain - writeln!(t.lock(), "installed targets:")?; + // show installed targets for the active toolchain + writeln!(t.lock(), "installed targets:")?; - for target in active_toolchain_targets { - writeln!(t.lock(), " {target}")?; - } - } - None => { - writeln!(t.lock(), "no active toolchain")?; + for target in active_toolchain_targets { + writeln!(t.lock(), " {target}")?; } } + None => { + writeln!(t.lock(), "no active toolchain")?; + } } fn print_header(t: &mut ColorableTerminal, text: &str) -> Result<(), Error> { From f20dea6a04667a0d5616127f878c9123f081d6d7 Mon Sep 17 00:00:00 2001 From: rami3l Date: Wed, 6 May 2026 22:13:35 +0200 Subject: [PATCH 4/8] refactor(cli/rustup-mode): reduce rightward drift in `show()` --- src/cli/rustup_mode.rs | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 7b2c598498..3accbe44b2 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -1197,27 +1197,25 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result { print_header(&mut t, "active toolchain")?; - match active_toolchain_and_source { - Some((active_toolchain_name, active_source)) => { - let active_toolchain = - Toolchain::with_source(cfg, active_toolchain_name.clone().into(), &active_source)?; - writeln!(t.lock(), "name: {}", active_toolchain.name())?; - writeln!(t.lock(), "active because: {}", active_source.to_reason())?; - if verbose { - writeln!(t.lock(), "compiler: {}", active_toolchain.rustc_version())?; - writeln!(t.lock(), "path: {}", active_toolchain.path().display())?; - } + let Some((active_toolchain_name, active_source)) = active_toolchain_and_source else { + writeln!(t.lock(), "no active toolchain")?; + return Ok(ExitCode::SUCCESS); + }; - // show installed targets for the active toolchain - writeln!(t.lock(), "installed targets:")?; + let active_toolchain = + Toolchain::with_source(cfg, active_toolchain_name.clone().into(), &active_source)?; + writeln!(t.lock(), "name: {}", active_toolchain.name())?; + writeln!(t.lock(), "active because: {}", active_source.to_reason())?; + if verbose { + writeln!(t.lock(), "compiler: {}", active_toolchain.rustc_version())?; + writeln!(t.lock(), "path: {}", active_toolchain.path().display())?; + } - for target in active_toolchain_targets { - writeln!(t.lock(), " {target}")?; - } - } - None => { - writeln!(t.lock(), "no active toolchain")?; - } + // show installed targets for the active toolchain + writeln!(t.lock(), "installed targets:")?; + + for target in active_toolchain_targets { + writeln!(t.lock(), " {target}")?; } fn print_header(t: &mut ColorableTerminal, text: &str) -> Result<(), Error> { From 11d5bdee62a8140f235f20d52770d32d74a6530e Mon Sep 17 00:00:00 2001 From: rami3l Date: Wed, 6 May 2026 21:46:01 +0200 Subject: [PATCH 5/8] refactor(cli/rustup-mode): postpone eval of `active_toolchain` in `show()` --- src/cli/rustup_mode.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 3accbe44b2..bff6003780 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -1202,10 +1202,11 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result { return Ok(ExitCode::SUCCESS); }; + writeln!(t.lock(), "name: {active_toolchain_name}")?; + writeln!(t.lock(), "active because: {}", active_source.to_reason())?; + let active_toolchain = Toolchain::with_source(cfg, active_toolchain_name.clone().into(), &active_source)?; - writeln!(t.lock(), "name: {}", active_toolchain.name())?; - writeln!(t.lock(), "active because: {}", active_source.to_reason())?; if verbose { writeln!(t.lock(), "compiler: {}", active_toolchain.rustc_version())?; writeln!(t.lock(), "path: {}", active_toolchain.path().display())?; From 42a4c2a198d1c53ba09d32178371cefca2bfea94 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 5 May 2026 22:27:42 +0200 Subject: [PATCH 6/8] refactor(cli/rustup-mode): postpone eval of `active_toolchain_targets` in `show()` --- src/cli/rustup_mode.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index bff6003780..665570a3e4 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -1143,21 +1143,6 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result { .map(|atar| (&atar.0, &atar.1)) .unzip(); - let active_toolchain_targets = match active_toolchain_name { - Some(ToolchainName::Official(desc)) => DistributableToolchain::new(cfg, desc.clone())? - .components()? - .into_iter() - .filter_map(|c| { - (c.installed && c.component.short_name() == "rust-std") - .then(|| c.component.target.expect("rust-std should have a target")) - }) - .collect(), - Some(ToolchainName::Custom(name)) => { - Toolchain::new(cfg, LocalToolchainName::Named(name.into()))?.installed_targets()? - } - None => Vec::new(), - }; - // show installed toolchains print_header(&mut t, "installed toolchains")?; @@ -1215,6 +1200,20 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result { // show installed targets for the active toolchain writeln!(t.lock(), "installed targets:")?; + let active_toolchain_targets = match active_toolchain_name { + ToolchainName::Official(desc) => DistributableToolchain::new(cfg, desc.clone())? + .components()? + .into_iter() + .filter_map(|c| { + (c.installed && c.component.short_name() == "rust-std") + .then(|| c.component.target.expect("rust-std should have a target")) + }) + .collect(), + ToolchainName::Custom(name) => { + Toolchain::new(cfg, LocalToolchainName::Named(name.into()))?.installed_targets()? + } + }; + for target in active_toolchain_targets { writeln!(t.lock(), " {target}")?; } From 328a1824540381bdfe21b95dd041d81382103bf4 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 5 May 2026 22:21:16 +0200 Subject: [PATCH 7/8] fix(cli/rustup-mode)!: complete `rustup show` if active toolchain is not installed --- src/cli/rustup_mode.rs | 55 ++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 665570a3e4..a9e09e233d 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -1190,32 +1190,41 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result { writeln!(t.lock(), "name: {active_toolchain_name}")?; writeln!(t.lock(), "active because: {}", active_source.to_reason())?; - let active_toolchain = - Toolchain::with_source(cfg, active_toolchain_name.clone().into(), &active_source)?; - if verbose { - writeln!(t.lock(), "compiler: {}", active_toolchain.rustc_version())?; - writeln!(t.lock(), "path: {}", active_toolchain.path().display())?; - } + match Toolchain::new(cfg, active_toolchain_name.clone().into()) { + Ok(active_toolchain) => { + if verbose { + writeln!(t.lock(), "compiler: {}", active_toolchain.rustc_version())?; + writeln!(t.lock(), "path: {}", active_toolchain.path().display())?; + } - // show installed targets for the active toolchain - writeln!(t.lock(), "installed targets:")?; + // show installed targets for the active toolchain + writeln!(t.lock(), "installed targets:")?; + + let active_toolchain_targets = match active_toolchain_name { + ToolchainName::Official(desc) => DistributableToolchain::new(cfg, desc.clone())? + .components()? + .into_iter() + .filter_map(|c| { + (c.installed && c.component.short_name() == "rust-std") + .then(|| c.component.target.expect("rust-std should have a target")) + }) + .collect(), + ToolchainName::Custom(name) => { + Toolchain::new(cfg, LocalToolchainName::Named(name.into()))? + .installed_targets()? + } + }; - let active_toolchain_targets = match active_toolchain_name { - ToolchainName::Official(desc) => DistributableToolchain::new(cfg, desc.clone())? - .components()? - .into_iter() - .filter_map(|c| { - (c.installed && c.component.short_name() == "rust-std") - .then(|| c.component.target.expect("rust-std should have a target")) - }) - .collect(), - ToolchainName::Custom(name) => { - Toolchain::new(cfg, LocalToolchainName::Named(name.into()))?.installed_targets()? + for target in active_toolchain_targets { + writeln!(t.lock(), " {target}")?; + } } - }; - - for target in active_toolchain_targets { - writeln!(t.lock(), " {target}")?; + Err( + RustupError::ToolchainNotInstalled { .. } | RustupError::PathToolchainNotInstalled(..), + ) => { + info!("the active toolchain `{active_toolchain_name}` is not installed"); + } + Err(e) => return Err(e.into()), } fn print_header(t: &mut ColorableTerminal, text: &str) -> Result<(), Error> { From 326e48dcb74e888e028f95280dafe1a4bda7ee77 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 28 Apr 2026 22:01:08 +0200 Subject: [PATCH 8/8] fix(cli/rustup-mode)!: skip auto-installation in some `rustup` commands --- src/cli/rustup_mode.rs | 51 +++++++++++++++++++++++++++++++++++---- tests/suite/cli_misc.rs | 12 ++++----- tests/suite/cli_rustup.rs | 28 ++++++++------------- tests/suite/cli_v2.rs | 6 ++--- 4 files changed, 65 insertions(+), 32 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index a9e09e233d..ad398e2a48 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -301,6 +301,36 @@ fn update_toolchain_value_parser(s: &str) -> Result { }) } +impl RustupSubcmd { + fn allow_auto_install(&self) -> bool { + match self { + // These subcommands execute or rely on the active toolchain, so auto-installing it when + // missing may be reasonable depending on the user's decision. + #[cfg(not(windows))] + RustupSubcmd::Man { .. } => true, + RustupSubcmd::Doc { .. } | RustupSubcmd::Run { .. } => true, + + // These subcommands don't require the active toolchain, so auto-installing it should be + // disabled to avoid surprises. + RustupSubcmd::Check { .. } + | RustupSubcmd::Completions { .. } + | RustupSubcmd::Component { .. } + | RustupSubcmd::Default { .. } + | RustupSubcmd::DumpTestament + | RustupSubcmd::Install { .. } + | RustupSubcmd::Override { .. } + | RustupSubcmd::Self_ { .. } + | RustupSubcmd::Set { .. } + | RustupSubcmd::Show { .. } + | RustupSubcmd::Target { .. } + | RustupSubcmd::Toolchain { .. } + | RustupSubcmd::Uninstall { .. } + | RustupSubcmd::Update { .. } + | RustupSubcmd::Which { .. } => false, + } + } +} + #[derive(Debug, Subcommand)] enum ShowSubcmd { /// Show the active toolchain @@ -631,15 +661,20 @@ pub async fn main( update_console_filter(process, &console_filter, matches.quiet, matches.verbose); - let cfg = &mut Cfg::from_env(current_dir, matches.quiet, true, process)?; - cfg.toolchain_override = matches.plus_toolchain; - let Some(subcmd) = matches.subcmd else { let help = Rustup::command().render_long_help(); writeln!(process.stderr().lock(), "{}", help.ansi())?; return Ok(ExitCode::FAILURE); }; + let cfg = &mut Cfg::from_env( + current_dir, + matches.quiet, + subcmd.allow_auto_install(), + process, + )?; + cfg.toolchain_override = matches.plus_toolchain; + match subcmd { RustupSubcmd::DumpTestament => common::dump_testament(process), RustupSubcmd::Install { opts } => update(cfg, opts, true).await, @@ -1968,8 +2003,8 @@ fn output_completion_script( } async fn display_version(current_dir: PathBuf, process: &Process) -> Result<()> { - info!("This is the version for the rustup toolchain manager, not the rustc compiler."); - let mut cfg = Cfg::from_env(current_dir, true, true, process)?; + info!("this is the version for the rustup toolchain manager, not the rustc compiler"); + let mut cfg = Cfg::from_env(current_dir, true, false, process)?; cfg.toolchain_override = cfg .process .args() @@ -1982,6 +2017,12 @@ async fn display_version(current_dir: PathBuf, process: &Process) -> Result<()> "the currently active `rustc` version is `{}`", tc.rustc_version() ), + Err(RustupError::ToolchainNotInstalled { + name, + is_active: true, + }) => { + info!("the active toolchain `{name}` is not installed"); + } Err(err) => error!("failed to display the current `rustc` version: {err}"), }, Ok(None) => info!("no `rustc` is currently active"), diff --git a/tests/suite/cli_misc.rs b/tests/suite/cli_misc.rs index ebdc6c1d22..5316a2db84 100644 --- a/tests/suite/cli_misc.rs +++ b/tests/suite/cli_misc.rs @@ -26,7 +26,7 @@ async fn version_mentions_rustc_version_confusion() { .await .with_stderr(snapbox::str![[r#" ... -info: This is the version for the rustup toolchain manager, not the rustc compiler. +info: this is the version for the rustup toolchain manager, not the rustc compiler ... "#]]) .is_ok(); @@ -1383,11 +1383,11 @@ async fn which_asking_uninstalled_toolchain() { cx.config .expect(["rustup", "which", "--toolchain=nightly", "rustc"]) .await - .with_stdout(snapbox::str![[r#" -[..]/toolchains/nightly-[HOST_TUPLE]/bin/rustc[EXE] - + .with_stderr(snapbox::str![[r#" +error: toolchain 'nightly-[HOST_TUPLE]' is not installed +... "#]]) - .is_ok(); + .is_err(); } #[tokio::test] @@ -1512,7 +1512,7 @@ active because: overridden by +toolchain on the command line .expect(["rustup", "+foo", "which", "rustc"]) .await .with_stderr(snapbox::str![[r#" -error: override toolchain 'foo' is not installed: the +toolchain on the command line specifies an uninstalled toolchain +error:[..] toolchain 'foo' is not installed[..] "#]]) .is_err(); diff --git a/tests/suite/cli_rustup.rs b/tests/suite/cli_rustup.rs index f164cb8d3c..82fd9278d1 100644 --- a/tests/suite/cli_rustup.rs +++ b/tests/suite/cli_rustup.rs @@ -1218,14 +1218,21 @@ async fn show_toolchain_toolchain_file_override_not_installed() { Default host: [HOST_TUPLE] rustup home: [RUSTUP_DIR] +installed toolchains +-------------------- +stable-[HOST_TUPLE] (default) + +active toolchain +---------------- +name: nightly-[HOST_TUPLE] +active because: overridden by '[TOOLCHAIN_FILE]' "#]]) .with_stderr(snapbox::str![[r#" -error: toolchain 'nightly-[HOST_TUPLE]' is not installed -help: run `rustup toolchain install` to install it +info: the active toolchain `nightly-[HOST_TUPLE]` is not installed "#]]) - .is_err(); + .is_ok(); } #[tokio::test] @@ -1254,22 +1261,9 @@ active toolchain ---------------- name: nightly-[HOST_TUPLE] active because: directory override for '[..]' -installed targets: - [HOST_TUPLE] "#]]) .is_ok(); - cx.config - .expect(["rustup", "component", "list", "--installed"]) - .await - .is_ok() - .with_stdout(snapbox::str![[r#" -cargo-[HOST_TUPLE] -rust-docs-[HOST_TUPLE] -rust-std-[HOST_TUPLE] -rustc-[HOST_TUPLE] - -"#]]); } #[tokio::test] @@ -1370,8 +1364,6 @@ active toolchain ---------------- name: nightly-[HOST_TUPLE] active because: overridden by environment variable RUSTUP_TOOLCHAIN -installed targets: - [HOST_TUPLE] "#]]); } diff --git a/tests/suite/cli_v2.rs b/tests/suite/cli_v2.rs index cfc84af3ed..73eda294a6 100644 --- a/tests/suite/cli_v2.rs +++ b/tests/suite/cli_v2.rs @@ -1210,7 +1210,7 @@ async fn set_auto_install_disable() { .await .is_ok(); cx.config - .expect(["rustup", "target", "list", "--toolchain=nightly"]) + .expect(["cargo", "+nightly", "--version"]) .await .with_stderr(snapbox::str![[r#" ... @@ -1220,7 +1220,7 @@ error: toolchain 'nightly-[HOST_TUPLE]' is not installed .is_err(); cx.config .expect_with_env( - ["rustup", "target", "list", "--toolchain=nightly"], + ["cargo", "+nightly", "--version"], [("RUSTUP_AUTO_INSTALL", "0")], ) .await @@ -1233,7 +1233,7 @@ error: toolchain 'nightly-[HOST_TUPLE]' is not installed // The environment variable takes precedence over the setting. cx.config .expect_with_env( - ["rustup", "target", "list", "--toolchain=nightly"], + ["cargo", "+nightly", "--version"], [("RUSTUP_AUTO_INSTALL", "1")], ) .await