@@ -515,43 +515,35 @@ impl<'a> Cfg<'a> {
515
515
pub ( crate ) fn find_active_toolchain (
516
516
& self ,
517
517
) -> Result < Option < ( LocalToolchainName , ActiveReason ) > > {
518
- Ok (
519
- if let Some ( ( override_config, reason) ) = self . find_override_config ( ) ? {
518
+ Ok ( match self . find_override_config ( ) ? {
519
+ Some ( ( override_config, reason) ) => {
520
520
Some ( ( override_config. into_local_toolchain_name ( ) , reason) )
521
- } else {
522
- self . get_default ( ) ?
523
- . map ( |x| ( x . into ( ) , ActiveReason :: Default ) )
524
- } ,
525
- )
521
+ }
522
+ _ => self
523
+ . get_default ( ) ?
524
+ . map ( |x| ( x . into ( ) , ActiveReason :: Default ) ) ,
525
+ } )
526
526
}
527
527
528
528
fn find_override_config ( & self ) -> Result < Option < ( OverrideCfg , ActiveReason ) > > {
529
529
let override_config: Option < ( OverrideCfg , ActiveReason ) > =
530
530
// First check +toolchain override from the command line
531
- if let Some ( ref name) = self . toolchain_override {
531
+ match self . toolchain_override { Some ( ref name) => {
532
532
let override_config = name. resolve ( & self . get_default_host_triple ( ) ?) ?. into ( ) ;
533
533
Some ( ( override_config, ActiveReason :: CommandLine ) )
534
- }
535
- // Then check the RUSTUP_TOOLCHAIN environment variable
536
- else if let Some ( ref name) = self . env_override {
534
+ } _ => { match self . env_override { Some ( ref name) => {
537
535
// Because path based toolchain files exist, this has to support
538
536
// custom, distributable, and absolute path toolchains otherwise
539
537
// rustup's export of a RUSTUP_TOOLCHAIN when running a process will
540
538
// error when a nested rustup invocation occurs
541
539
Some ( ( name. clone ( ) . into ( ) , ActiveReason :: Environment ) )
542
- }
543
- // Then walk up the directory tree from 'path' looking for either the
544
- // directory in the override database, or a `rust-toolchain{.toml}` file,
545
- // in that order.
546
- else if let Some ( ( override_cfg, active_reason) ) = self . settings_file . with ( |s| {
540
+ } _ => { match self . settings_file . with ( |s| {
547
541
self . find_override_from_dir_walk ( & self . current_dir , s)
548
- } ) ? {
542
+ } ) ? { Some ( ( override_cfg , active_reason ) ) => {
549
543
Some ( ( override_cfg, active_reason) )
550
- }
551
- // Otherwise, there is no override.
552
- else {
544
+ } _ => {
553
545
None
554
- } ;
546
+ } } } } } } ;
555
547
556
548
Ok ( override_config)
557
549
}
@@ -751,39 +743,55 @@ impl<'a> Cfg<'a> {
751
743
force_non_host : bool ,
752
744
verbose : bool ,
753
745
) -> Result < ( LocalToolchainName , ActiveReason ) > {
754
- if let Some ( ( override_config, reason) ) = self . find_override_config ( ) ? {
755
- let toolchain = override_config. clone ( ) . into_local_toolchain_name ( ) ;
756
- if let OverrideCfg :: Official {
757
- toolchain,
758
- components,
759
- targets,
760
- profile,
761
- } = override_config
762
- {
763
- self . ensure_installed (
764
- & toolchain,
765
- components,
766
- targets,
767
- profile,
768
- force_non_host,
769
- verbose,
770
- )
771
- . await ?;
772
- } else {
773
- Toolchain :: with_reason ( self , toolchain. clone ( ) , & reason) ?;
774
- }
775
- Ok ( ( toolchain, reason) )
776
- } else if let Some ( toolchain) = self . get_default ( ) ? {
777
- let reason = ActiveReason :: Default ;
778
- if let ToolchainName :: Official ( desc) = & toolchain {
779
- self . ensure_installed ( desc, vec ! [ ] , vec ! [ ] , None , force_non_host, verbose)
780
- . await ?;
781
- } else {
782
- Toolchain :: with_reason ( self , toolchain. clone ( ) . into ( ) , & reason) ?;
746
+ match self . find_override_config ( ) ? {
747
+ Some ( ( override_config, reason) ) => {
748
+ let toolchain = override_config. clone ( ) . into_local_toolchain_name ( ) ;
749
+ match override_config {
750
+ OverrideCfg :: Official {
751
+ toolchain,
752
+ components,
753
+ targets,
754
+ profile,
755
+ } => {
756
+ self . ensure_installed (
757
+ & toolchain,
758
+ components,
759
+ targets,
760
+ profile,
761
+ force_non_host,
762
+ verbose,
763
+ )
764
+ . await ?;
765
+ }
766
+ _ => {
767
+ Toolchain :: with_reason ( self , toolchain. clone ( ) , & reason) ?;
768
+ }
769
+ }
770
+ Ok ( ( toolchain, reason) )
783
771
}
784
- Ok ( ( toolchain. into ( ) , reason) )
785
- } else {
786
- Err ( no_toolchain_error ( self . process ) )
772
+ _ => match self . get_default ( ) ? {
773
+ Some ( toolchain) => {
774
+ let reason = ActiveReason :: Default ;
775
+ match & toolchain {
776
+ ToolchainName :: Official ( desc) => {
777
+ self . ensure_installed (
778
+ desc,
779
+ vec ! [ ] ,
780
+ vec ! [ ] ,
781
+ None ,
782
+ force_non_host,
783
+ verbose,
784
+ )
785
+ . await ?;
786
+ }
787
+ _ => {
788
+ Toolchain :: with_reason ( self , toolchain. clone ( ) . into ( ) , & reason) ?;
789
+ }
790
+ }
791
+ Ok ( ( toolchain. into ( ) , reason) )
792
+ }
793
+ _ => Err ( no_toolchain_error ( self . process ) ) ,
794
+ } ,
787
795
}
788
796
}
789
797
@@ -891,12 +899,9 @@ impl<'a> Cfg<'a> {
891
899
pub ( crate ) fn list_channels ( & self ) -> Result < Vec < ( ToolchainDesc , DistributableToolchain < ' _ > ) > > {
892
900
self . list_toolchains ( ) ?
893
901
. into_iter ( )
894
- . filter_map ( |t| {
895
- if let ToolchainName :: Official ( desc) = t {
896
- Some ( desc)
897
- } else {
898
- None
899
- }
902
+ . filter_map ( |t| match t {
903
+ ToolchainName :: Official ( desc) => Some ( desc) ,
904
+ _ => None ,
900
905
} )
901
906
. filter ( ToolchainDesc :: is_tracking)
902
907
. map ( |n| {
0 commit comments