@@ -115,7 +115,7 @@ impl Display for ActiveReason {
115115// RUSTUP_TOOLCHAIN environment variable, or rust-toolchain.toml file etc. Can
116116// include components and targets from a rust-toolchain.toml that should be
117117// downloaded and installed.
118- #[ derive( Debug ) ]
118+ #[ derive( Clone , Debug ) ]
119119enum OverrideCfg {
120120 PathBased ( PathBasedToolchainName ) ,
121121 Custom ( CustomToolchainName ) ,
@@ -744,45 +744,32 @@ impl<'a> Cfg<'a> {
744744 & self ,
745745 verbose : bool ,
746746 ) -> Result < ( LocalToolchainName , ActiveReason ) > {
747- match self . find_override_config ( ) ? {
748- Some ( ( override_config, reason) ) => match override_config {
749- OverrideCfg :: PathBased ( path_based_name) => {
750- let toolchain = Toolchain :: with_reason ( self , path_based_name. into ( ) , & reason) ?;
751- Ok ( ( toolchain. name ( ) . clone ( ) , reason) )
752- }
753- OverrideCfg :: Custom ( custom_name) => {
754- let toolchain = Toolchain :: with_reason ( self , custom_name. into ( ) , & reason) ?;
755- Ok ( ( toolchain. name ( ) . clone ( ) , reason) )
756- }
757- OverrideCfg :: Official {
758- toolchain,
759- components,
760- targets,
761- profile,
762- } => {
763- let toolchain = self
764- . ensure_installed ( & toolchain, components, targets, profile, verbose)
765- . await ?
766- . 1 ;
767- Ok ( ( toolchain. name ( ) . clone ( ) , reason) )
768- }
769- } ,
770- None => match self . get_default ( ) ? {
771- None => Err ( no_toolchain_error ( self . process ) ) ,
772- Some ( ToolchainName :: Custom ( custom_name) ) => {
773- let reason = ActiveReason :: Default ;
774- let toolchain = Toolchain :: with_reason ( self , custom_name. into ( ) , & reason) ?;
775- Ok ( ( toolchain. name ( ) . clone ( ) , reason) )
776- }
777- Some ( ToolchainName :: Official ( toolchain_desc) ) => {
778- let reason = ActiveReason :: Default ;
779- let toolchain = self
780- . ensure_installed ( & toolchain_desc, vec ! [ ] , vec ! [ ] , None , verbose)
781- . await ?
782- . 1 ;
783- Ok ( ( toolchain. name ( ) . clone ( ) , reason) )
784- }
785- } ,
747+ if let Some ( ( override_config, reason) ) = self . find_override_config ( ) ? {
748+ let toolchain = override_config. clone ( ) . into_local_toolchain_name ( ) ;
749+ if let OverrideCfg :: Official {
750+ toolchain,
751+ components,
752+ targets,
753+ profile,
754+ } = override_config
755+ {
756+ self . ensure_installed ( & toolchain, components, targets, profile, verbose)
757+ . await ?;
758+ } else {
759+ Toolchain :: with_reason ( self , toolchain. clone ( ) , & reason) ?;
760+ }
761+ Ok ( ( toolchain, reason) )
762+ } else if let Some ( toolchain) = self . get_default ( ) ? {
763+ let reason = ActiveReason :: Default ;
764+ if let ToolchainName :: Official ( desc) = & toolchain {
765+ self . ensure_installed ( desc, vec ! [ ] , vec ! [ ] , None , verbose)
766+ . await ?;
767+ } else {
768+ Toolchain :: with_reason ( self , toolchain. clone ( ) . into ( ) , & reason) ?;
769+ }
770+ Ok ( ( toolchain. into ( ) , reason) )
771+ } else {
772+ Err ( no_toolchain_error ( self . process ) )
786773 }
787774 }
788775
0 commit comments