@@ -301,6 +301,36 @@ fn update_toolchain_value_parser(s: &str) -> Result<PartialToolchainDesc> {
301301 } )
302302}
303303
304+ impl RustupSubcmd {
305+ fn allow_auto_install ( & self ) -> bool {
306+ match self {
307+ // These subcommands execute or rely on the active toolchain, so auto-installing it when
308+ // missing may be reasonable depending on the user's decision.
309+ #[ cfg( not( windows) ) ]
310+ RustupSubcmd :: Man { .. } => true ,
311+ RustupSubcmd :: Doc { .. } | RustupSubcmd :: Run { .. } => true ,
312+
313+ // These subcommands don't require the active toolchain, so auto-installing it should be
314+ // disabled to avoid surprises.
315+ RustupSubcmd :: Check { .. }
316+ | RustupSubcmd :: Completions { .. }
317+ | RustupSubcmd :: Component { .. }
318+ | RustupSubcmd :: Default { .. }
319+ | RustupSubcmd :: DumpTestament
320+ | RustupSubcmd :: Install { .. }
321+ | RustupSubcmd :: Override { .. }
322+ | RustupSubcmd :: Self_ { .. }
323+ | RustupSubcmd :: Set { .. }
324+ | RustupSubcmd :: Show { .. }
325+ | RustupSubcmd :: Target { .. }
326+ | RustupSubcmd :: Toolchain { .. }
327+ | RustupSubcmd :: Uninstall { .. }
328+ | RustupSubcmd :: Update { .. }
329+ | RustupSubcmd :: Which { .. } => false ,
330+ }
331+ }
332+ }
333+
304334#[ derive( Debug , Subcommand ) ]
305335enum ShowSubcmd {
306336 /// Show the active toolchain
@@ -631,15 +661,20 @@ pub async fn main(
631661
632662 update_console_filter ( process, & console_filter, matches. quiet , matches. verbose ) ;
633663
634- let cfg = & mut Cfg :: from_env ( current_dir, matches. quiet , true , process) ?;
635- cfg. toolchain_override = matches. plus_toolchain ;
636-
637664 let Some ( subcmd) = matches. subcmd else {
638665 let help = Rustup :: command ( ) . render_long_help ( ) ;
639666 writeln ! ( process. stderr( ) . lock( ) , "{}" , help. ansi( ) ) ?;
640667 return Ok ( ExitCode :: FAILURE ) ;
641668 } ;
642669
670+ let cfg = & mut Cfg :: from_env (
671+ current_dir,
672+ matches. quiet ,
673+ subcmd. allow_auto_install ( ) ,
674+ process,
675+ ) ?;
676+ cfg. toolchain_override = matches. plus_toolchain ;
677+
643678 match subcmd {
644679 RustupSubcmd :: DumpTestament => common:: dump_testament ( process) ,
645680 RustupSubcmd :: Install { opts } => update ( cfg, opts, true ) . await ,
0 commit comments