@@ -684,38 +684,51 @@ impl Cfg {
684
684
Ok ( ( Toolchain :: new ( self , toolchain) ?, reason) )
685
685
}
686
686
Some ( LocalToolchainName :: Named ( ToolchainName :: Official ( desc) ) ) => {
687
- let components: Vec < _ > = components. iter ( ) . map ( AsRef :: as_ref) . collect ( ) ;
688
- let targets: Vec < _ > = targets. iter ( ) . map ( AsRef :: as_ref) . collect ( ) ;
689
- let toolchain = match DistributableToolchain :: new ( self , desc. clone ( ) ) {
690
- Err ( RustupError :: ToolchainNotInstalled ( _) ) => {
691
- DistributableToolchain :: install (
692
- self ,
693
- & desc,
694
- & components,
695
- & targets,
696
- profile. unwrap_or ( Profile :: Default ) ,
697
- false ,
698
- ) ?
699
- . 1
700
- }
701
- Ok ( mut distributable) => {
702
- if !distributable. components_exist ( & components, & targets) ? {
703
- distributable. update (
704
- & components,
705
- & targets,
706
- profile. unwrap_or ( Profile :: Default ) ,
707
- ) ?;
708
- }
709
- distributable
710
- }
711
- Err ( e) => return Err ( e. into ( ) ) ,
712
- }
713
- . into ( ) ;
687
+ let toolchain = self . ensure_installed ( desc, components, targets, profile) ?;
714
688
Ok ( ( toolchain, reason) )
715
689
}
716
690
}
717
691
}
718
692
693
+ // Returns a Toolchain matching the given ToolchainDesc, installing it and
694
+ // the given components and targets if they aren't already installed.
695
+ fn ensure_installed (
696
+ & self ,
697
+ toolchain : ToolchainDesc ,
698
+ components : Vec < String > ,
699
+ targets : Vec < String > ,
700
+ profile : Option < Profile > ,
701
+ ) -> Result < Toolchain < ' _ > > {
702
+ let components: Vec < _ > = components. iter ( ) . map ( AsRef :: as_ref) . collect ( ) ;
703
+ let targets: Vec < _ > = targets. iter ( ) . map ( AsRef :: as_ref) . collect ( ) ;
704
+ let toolchain = match DistributableToolchain :: new ( self , toolchain. clone ( ) ) {
705
+ Err ( RustupError :: ToolchainNotInstalled ( _) ) => {
706
+ DistributableToolchain :: install (
707
+ self ,
708
+ & toolchain,
709
+ & components,
710
+ & targets,
711
+ profile. unwrap_or ( Profile :: Default ) ,
712
+ false ,
713
+ ) ?
714
+ . 1
715
+ }
716
+ Ok ( mut distributable) => {
717
+ if !distributable. components_exist ( & components, & targets) ? {
718
+ distributable. update (
719
+ & components,
720
+ & targets,
721
+ profile. unwrap_or ( Profile :: Default ) ,
722
+ ) ?;
723
+ }
724
+ distributable
725
+ }
726
+ Err ( e) => return Err ( e. into ( ) ) ,
727
+ }
728
+ . into ( ) ;
729
+ Ok ( toolchain)
730
+ }
731
+
719
732
/// Get the configured default toolchain.
720
733
/// If none is configured, returns None
721
734
/// If a bad toolchain name is configured, errors.
0 commit comments