@@ -409,7 +409,7 @@ impl Cfg {
409409 }
410410
411411 pub fn which_binary ( & self , path : & Path , binary : & str ) -> Result < Option < PathBuf > > {
412- let ( toolchain, _) = self . find_or_install_override_toolchain_or_default ( path) ?;
412+ let ( toolchain, _) = self . find_or_install_override_toolchain_or_default ( path, true ) ?;
413413 Ok ( Some ( toolchain. binary_file ( binary) ) )
414414 }
415415
@@ -620,6 +620,7 @@ impl Cfg {
620620 pub fn find_or_install_override_toolchain_or_default (
621621 & self ,
622622 path : & Path ,
623+ install : bool ,
623624 ) -> Result < ( Toolchain < ' _ > , Option < OverrideReason > ) > {
624625 fn components_exist (
625626 distributable : & DistributableToolchain < ' _ > ,
@@ -699,7 +700,9 @@ impl Cfg {
699700 let targets: Vec < _ > = targets. iter ( ) . map ( AsRef :: as_ref) . collect ( ) ;
700701
701702 let distributable = DistributableToolchain :: new ( & toolchain) ?;
702- if !toolchain. exists ( ) || !components_exist ( & distributable, & components, & targets) ?
703+ if install
704+ && ( !toolchain. exists ( )
705+ || !components_exist ( & distributable, & components, & targets) ?)
703706 {
704707 distributable. install_from_dist ( true , false , & components, & targets, profile) ?;
705708 }
@@ -789,15 +792,8 @@ impl Cfg {
789792 } )
790793 }
791794
792- pub fn toolchain_for_dir (
793- & self ,
794- path : & Path ,
795- ) -> Result < ( Toolchain < ' _ > , Option < OverrideReason > ) > {
796- self . find_or_install_override_toolchain_or_default ( path)
797- }
798-
799795 pub fn create_command_for_dir ( & self , path : & Path , binary : & str ) -> Result < Command > {
800- let ( ref toolchain, _) = self . toolchain_for_dir ( path) ?;
796+ let ( ref toolchain, _) = self . find_or_install_override_toolchain_or_default ( path, true ) ?;
801797
802798 if let Some ( cmd) = self . maybe_do_cargo_fallback ( toolchain, binary) ? {
803799 Ok ( cmd)
0 commit comments