From d7919dd3419bc05813798232698031f6c3313831 Mon Sep 17 00:00:00 2001
From: cyqsimon <28627918+cyqsimon@users.noreply.github.com>
Date: Wed, 15 Oct 2025 17:25:57 +0800
Subject: [PATCH 1/4] cli: add help text for `rustup self uninstall -y`
Help text is mirrored from `rustup-init -y`
---
src/cli/rustup_mode.rs | 1 +
.../rustup_self_cmd_uninstall_cmd_help_flag.stdout.term.svg | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs
index a3137c6f51..2619ad4df2 100644
--- a/src/cli/rustup_mode.rs
+++ b/src/cli/rustup_mode.rs
@@ -540,6 +540,7 @@ enum SelfSubcmd {
/// Uninstall rustup
Uninstall {
+ /// Disable confirmation prompt
#[arg(short = 'y')]
no_prompt: bool,
},
diff --git a/tests/suite/cli_rustup_ui/rustup_self_cmd_uninstall_cmd_help_flag.stdout.term.svg b/tests/suite/cli_rustup_ui/rustup_self_cmd_uninstall_cmd_help_flag.stdout.term.svg
index e164ee4fee..4c8fbc58ef 100644
--- a/tests/suite/cli_rustup_ui/rustup_self_cmd_uninstall_cmd_help_flag.stdout.term.svg
+++ b/tests/suite/cli_rustup_ui/rustup_self_cmd_uninstall_cmd_help_flag.stdout.term.svg
@@ -30,7 +30,7 @@
Options:
- -y
+ -y Disable confirmation prompt
-h, --help Print help
From e462360df526edbb98c6dde744ec9f0ca6590998 Mon Sep 17 00:00:00 2001
From: cyqsimon <28627918+cyqsimon@users.noreply.github.com>
Date: Wed, 15 Oct 2025 11:48:38 +0800
Subject: [PATCH 2/4] cli: add `rustup self uninstall --no-modify-path`
---
src/cli/rustup_mode.rs | 9 ++++-
src/cli/self_update.rs | 33 +++++++++++++++----
...md_uninstall_cmd_help_flag.stdout.term.svg | 10 +++---
3 files changed, 41 insertions(+), 11 deletions(-)
diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs
index 2619ad4df2..34f267dbc6 100644
--- a/src/cli/rustup_mode.rs
+++ b/src/cli/rustup_mode.rs
@@ -543,6 +543,10 @@ enum SelfSubcmd {
/// Disable confirmation prompt
#[arg(short = 'y')]
no_prompt: bool,
+
+ /// Do not clean up the `PATH` environment variable
+ #[arg(long)]
+ no_modify_path: bool,
},
/// Upgrade the internal data format
@@ -725,7 +729,10 @@ pub async fn main(
RustupSubcmd::Man { command, toolchain } => man(cfg, &command, toolchain).await,
RustupSubcmd::Self_ { subcmd } => match subcmd {
SelfSubcmd::Update => self_update::update(cfg).await,
- SelfSubcmd::Uninstall { no_prompt } => self_update::uninstall(no_prompt, process),
+ SelfSubcmd::Uninstall {
+ no_prompt,
+ no_modify_path,
+ } => self_update::uninstall(no_prompt, no_modify_path, process),
SelfSubcmd::UpgradeData => cfg.upgrade_data().map(|_| ExitCode(0)),
},
RustupSubcmd::Set { subcmd } => match subcmd {
diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs
index 5e1e7b78aa..ee09c72537 100644
--- a/src/cli/self_update.rs
+++ b/src/cli/self_update.rs
@@ -474,6 +474,17 @@ This will uninstall all Rust toolchains and data, and remove
};
}
+macro_rules! pre_uninstall_msg_no_modify_path {
+ () => {
+ r"# Thanks for hacking in Rust!
+
+This will uninstall all Rust toolchains and data.
+Your `PATH` environment variable will not be touched.
+
+"
+ };
+}
+
static DEFAULT_UPDATE_ROOT: &str = "https://static.rust-lang.org/rustup";
fn update_root(process: &Process) -> String {
@@ -968,7 +979,11 @@ async fn maybe_install_rust(opts: InstallOpts<'_>, cfg: &mut Cfg<'_>) -> Result<
Ok(())
}
-pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result {
+pub(crate) fn uninstall(
+ no_prompt: bool,
+ no_modify_path: bool,
+ process: &Process,
+) -> Result {
if cfg!(feature = "no-self-update") {
error!("self-uninstall is disabled for this build of rustup");
error!("you should probably use your system package manager to uninstall rustup");
@@ -983,10 +998,14 @@ pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result Result
+