@@ -71,6 +71,7 @@ pub struct InstallOpts<'a> {
7171 pub default_toolchain : Option < String > ,
7272 pub profile : String ,
7373 pub no_modify_path : bool ,
74+ pub no_update_toolchain : bool ,
7475 pub components : & ' a [ & ' a str ] ,
7576 pub targets : & ' a [ & ' a str ] ,
7677}
@@ -328,6 +329,7 @@ pub fn install(
328329 opts. default_toolchain . as_deref ( ) ,
329330 & opts. profile ,
330331 opts. default_host_triple . as_deref ( ) ,
332+ !opts. no_update_toolchain ,
331333 opts. components ,
332334 opts. targets ,
333335 verbose,
@@ -712,6 +714,7 @@ fn maybe_install_rust(
712714 toolchain : Option < & str > ,
713715 profile_str : & str ,
714716 default_host_triple : Option < & str > ,
717+ update_existing_toolchain : bool ,
715718 components : & [ & str ] ,
716719 targets : & [ & str ] ,
717720 verbose : bool ,
@@ -728,8 +731,10 @@ fn maybe_install_rust(
728731 info ! ( "default host triple is {}" , cfg. get_default_host_triple( ) ?) ;
729732 }
730733
731- let user_specified_something =
732- toolchain. is_some ( ) || !targets. is_empty ( ) || !components. is_empty ( ) ;
734+ let user_specified_something = toolchain. is_some ( )
735+ || !targets. is_empty ( )
736+ || !components. is_empty ( )
737+ || update_existing_toolchain;
733738
734739 // If the user specified they want no toolchain, we skip this, otherwise
735740 // if they specify something directly, or we have no default, then we install
@@ -754,16 +759,21 @@ fn maybe_install_rust(
754759 }
755760 writeln ! ( process( ) . stdout( ) ) ?;
756761 } else if user_specified_something || cfg. find_default ( ) ?. is_none ( ) {
757- let toolchain_str = toolchain. unwrap_or ( "stable" ) ;
758- let toolchain = cfg. get_toolchain ( toolchain_str, false ) ?;
762+ let ( toolchain_str, toolchain) = match toolchain {
763+ Some ( s) => ( s. to_owned ( ) , cfg. get_toolchain ( s, false ) ?) ,
764+ None => match cfg. find_default ( ) ? {
765+ Some ( t) => ( t. name ( ) . to_owned ( ) , t) ,
766+ None => ( "stable" . to_owned ( ) , cfg. get_toolchain ( "stable" , false ) ?) ,
767+ } ,
768+ } ;
759769 if toolchain. exists ( ) {
760770 warn ! ( "Updating existing toolchain, profile choice will be ignored" ) ;
761771 }
762772 let distributable = DistributableToolchain :: new ( & toolchain) ?;
763773 let status = distributable. install_from_dist ( true , false , components, targets) ?;
764- cfg. set_default ( toolchain_str) ?;
774+ cfg. set_default ( & toolchain_str) ?;
765775 writeln ! ( process( ) . stdout( ) ) ?;
766- common:: show_channel_update ( & cfg, toolchain_str, Ok ( status) ) ?;
776+ common:: show_channel_update ( & cfg, & toolchain_str, Ok ( status) ) ?;
767777 } else {
768778 info ! ( "updating existing rustup installation - leaving toolchains alone" ) ;
769779 writeln ! ( process( ) . stdout( ) ) ?;
0 commit comments