diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 5de45f0760..34baeae19b 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -3,6 +3,7 @@ use std::fmt; use std::io::Write; use std::path::{Path, PathBuf}; use std::process::ExitStatus; +use std::str::FromStr; use anyhow::{anyhow, Error, Result}; use clap::{builder::PossibleValue, Args, CommandFactory, Parser, Subcommand, ValueEnum}; @@ -135,7 +136,7 @@ enum RustupSubcmd { )] Update { /// Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see `rustup help toolchain` - #[arg(num_args = 1..)] + #[arg(num_args = 1.., value_parser = update_toolchain_value_parser)] toolchain: Vec, /// Don't perform self update when running the `rustup update` command @@ -258,6 +259,14 @@ enum RustupSubcmd { }, } +fn update_toolchain_value_parser(s: &str) -> Result { + PartialToolchainDesc::from_str(s).inspect_err(|_| { + if s == "self" { + info!("if you meant to update rustup itself, use `rustup self update`"); + } + }) +} + #[derive(Debug, Subcommand)] enum ShowSubcmd { /// Show the active toolchain diff --git a/src/toolchain.rs b/src/toolchain.rs index 6d3c8cb2fd..6c995cba7c 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -457,7 +457,13 @@ impl<'a> Toolchain<'a> { fs::remove_dir_all(&path)?; true } else { + let name = name.to_string(); info!("no toolchain installed for '{name}'"); + if name == "self" { + info!( + "if you meant to uninstall rustup itself, use `rustup self uninstall`" + ); + } false } }