diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 09d137965d..aee406444e 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -196,7 +196,7 @@ pub fn main() -> Result { ("self", c) => match c.subcommand() { Some(s) => match s { ("update", _) => self_update::update(cfg)?, - ("uninstall", m) => self_uninstall(m)?, + ("uninstall", m) => self_uninstall(cfg, m)?, _ => unreachable!(), }, None => unreachable!(), @@ -1635,10 +1635,9 @@ fn man(cfg: &Cfg, m: &ArgMatches) -> Result { Ok(utils::ExitCode(0)) } -fn self_uninstall(m: &ArgMatches) -> Result { - let no_prompt = m.get_flag("no-prompt"); - - self_update::uninstall(no_prompt) +fn self_uninstall(cfg: &Cfg, m: &ArgMatches<'_>) -> Result { + let no_prompt = m.is_present("no-prompt"); + self_update::uninstall(cfg, no_prompt) } fn set_default_host_triple(cfg: &Cfg, m: &ArgMatches) -> Result { diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index 267f26c5e0..da29bd49d4 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -903,7 +903,7 @@ fn _install_selection<'a>( }) } -pub(crate) fn uninstall(no_prompt: bool) -> Result { +pub(crate) fn uninstall(cfg: &Cfg, no_prompt: bool) -> Result { if NEVER_SELF_UPDATE { err!("self-uninstall is disabled for this build of rustup"); err!("you should probably use your system package manager to uninstall rustup"); @@ -926,6 +926,13 @@ pub(crate) fn uninstall(no_prompt: bool) -> Result { } } + info!("removing toolchains"); + let toolchains = cfg.list_toolchains()?; + for toolchain in toolchains { + let toolchain = cfg.get_toolchain(&toolchain, false)?; + toolchain.remove()?; + } + info!("removing rustup home"); // Delete RUSTUP_HOME diff --git a/tests/suite/cli_self_upd.rs b/tests/suite/cli_self_upd.rs index d20c502c98..13018fd390 100644 --- a/tests/suite/cli_self_upd.rs +++ b/tests/suite/cli_self_upd.rs @@ -153,6 +153,24 @@ fn uninstall_deletes_bins() { }); } +#[test] +fn uninstall_deletes_installed_toolchains() { + setup_installed(&|config| { + let path = config.customdir.join("custom-1"); + let path = path.to_string_lossy(); + config.expect_ok(&["rustup", "toolchain", "link", "custom", &path]); + config.expect_ok_contains( + &["rustup", "self", "uninstall", "-y"], + "", + r" +info: uninstalling toolchain 'custom' +info: toolchain 'custom' uninstalled +", + ); + assert!(!&config.rustupdir.join("toolchains").exists()) + }); +} + #[test] fn uninstall_works_if_some_bins_dont_exist() { setup_empty_installed(&|config| {