@@ -92,38 +92,39 @@ impl<T: Into<String>> From<T> for OverrideFile {
9292 }
9393}
9494
95- // Represents the reason why the active toolchain is active .
95+ // Represents the source that determined the current active toolchain.
9696#[ derive( Debug ) ]
97- pub ( crate ) enum ActiveReason {
97+ pub ( crate ) enum ActiveSource {
9898 Default ,
9999 Environment ,
100100 CommandLine ,
101101 OverrideDB ( PathBuf ) ,
102102 ToolchainFile ( PathBuf ) ,
103103}
104104
105- impl ActiveReason {
106- /// Format `ActiveReason` for setting the `RUSTUP_TOOLCHAIN_SOURCE` environment variable.
107- pub fn to_source ( & self ) -> & str {
105+ impl ActiveSource {
106+ pub fn to_reason ( & self ) -> String {
108107 match self {
108+ Self :: Default => String :: from ( "it's the default toolchain" ) ,
109+ Self :: Environment => {
110+ String :: from ( "overridden by environment variable RUSTUP_TOOLCHAIN" )
111+ }
112+ Self :: CommandLine => String :: from ( "overridden by +toolchain on the command line" ) ,
113+ Self :: OverrideDB ( path) => format ! ( "directory override for '{}'" , path. display( ) ) ,
114+ Self :: ToolchainFile ( path) => format ! ( "overridden by '{}'" , path. display( ) ) ,
115+ }
116+ }
117+ }
118+
119+ impl Display for ActiveSource {
120+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
121+ f. write_str ( match self {
109122 Self :: Default => "default" ,
110123 Self :: Environment => "env" ,
111124 Self :: CommandLine => "cli" ,
112125 Self :: OverrideDB ( _) => "path-override" ,
113126 Self :: ToolchainFile ( _) => "toolchain-file" ,
114- }
115- }
116- }
117-
118- impl Display for ActiveReason {
119- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> std:: result:: Result < ( ) , fmt:: Error > {
120- match self {
121- Self :: Default => write ! ( f, "it's the default toolchain" ) ,
122- Self :: Environment => write ! ( f, "overridden by environment variable RUSTUP_TOOLCHAIN" ) ,
123- Self :: CommandLine => write ! ( f, "overridden by +toolchain on the command line" ) ,
124- Self :: OverrideDB ( path) => write ! ( f, "directory override for '{}'" , path. display( ) ) ,
125- Self :: ToolchainFile ( path) => write ! ( f, "overridden by '{}'" , path. display( ) ) ,
126- }
127+ } )
127128 }
128129}
129130
@@ -518,7 +519,7 @@ impl<'a> Cfg<'a> {
518519 pub ( crate ) async fn maybe_ensure_active_toolchain (
519520 & self ,
520521 force_ensure : Option < bool > ,
521- ) -> Result < Option < ( LocalToolchainName , ActiveReason ) > > {
522+ ) -> Result < Option < ( LocalToolchainName , ActiveSource ) > > {
522523 let should_ensure = if let Some ( force) = force_ensure {
523524 force
524525 } else {
@@ -537,39 +538,39 @@ impl<'a> Cfg<'a> {
537538 }
538539 }
539540
540- pub ( crate ) fn active_toolchain ( & self ) -> Result < Option < ( LocalToolchainName , ActiveReason ) > > {
541+ pub ( crate ) fn active_toolchain ( & self ) -> Result < Option < ( LocalToolchainName , ActiveSource ) > > {
541542 Ok (
542- if let Some ( ( override_config, reason ) ) = self . find_override_config ( ) ? {
543- Some ( ( override_config. into_local_toolchain_name ( ) , reason ) )
543+ if let Some ( ( override_config, source ) ) = self . find_override_config ( ) ? {
544+ Some ( ( override_config. into_local_toolchain_name ( ) , source ) )
544545 } else {
545546 self . get_default ( ) ?
546- . map ( |x| ( x. into ( ) , ActiveReason :: Default ) )
547+ . map ( |x| ( x. into ( ) , ActiveSource :: Default ) )
547548 } ,
548549 )
549550 }
550551
551- fn find_override_config ( & self ) -> Result < Option < ( OverrideCfg , ActiveReason ) > > {
552- let override_config: Option < ( OverrideCfg , ActiveReason ) > =
552+ fn find_override_config ( & self ) -> Result < Option < ( OverrideCfg , ActiveSource ) > > {
553+ let override_config: Option < ( OverrideCfg , ActiveSource ) > =
553554 // First check +toolchain override from the command line
554555 if let Some ( name) = & self . toolchain_override {
555556 let override_config = name. resolve ( & self . get_default_host_triple ( ) ?) ?. into ( ) ;
556- Some ( ( override_config, ActiveReason :: CommandLine ) )
557+ Some ( ( override_config, ActiveSource :: CommandLine ) )
557558 }
558559 // Then check the RUSTUP_TOOLCHAIN environment variable
559560 else if let Some ( name) = & self . env_override {
560561 // Because path based toolchain files exist, this has to support
561562 // custom, distributable, and absolute path toolchains otherwise
562563 // rustup's export of a RUSTUP_TOOLCHAIN when running a process will
563564 // error when a nested rustup invocation occurs
564- Some ( ( name. clone ( ) . into ( ) , ActiveReason :: Environment ) )
565+ Some ( ( name. clone ( ) . into ( ) , ActiveSource :: Environment ) )
565566 }
566567 // Then walk up the directory tree from 'path' looking for either the
567568 // directory in the override database, or a `rust-toolchain{.toml}` file,
568569 // in that order.
569- else if let Some ( ( override_cfg, active_reason ) ) = self . settings_file . with ( |s| {
570+ else if let Some ( ( override_cfg, active_source ) ) = self . settings_file . with ( |s| {
570571 self . find_override_from_dir_walk ( & self . current_dir , s)
571572 } ) ? {
572- Some ( ( override_cfg, active_reason ) )
573+ Some ( ( override_cfg, active_source ) )
573574 }
574575 // Otherwise, there is no override.
575576 else {
@@ -583,13 +584,13 @@ impl<'a> Cfg<'a> {
583584 & self ,
584585 dir : & Path ,
585586 settings : & Settings ,
586- ) -> Result < Option < ( OverrideCfg , ActiveReason ) > > {
587+ ) -> Result < Option < ( OverrideCfg , ActiveSource ) > > {
587588 let mut dir = Some ( dir) ;
588589
589590 while let Some ( d) = dir {
590591 // First check the override database
591592 if let Some ( name) = settings. dir_override ( d) {
592- let reason = ActiveReason :: OverrideDB ( d. to_owned ( ) ) ;
593+ let source = ActiveSource :: OverrideDB ( d. to_owned ( ) ) ;
593594 // Note that `rustup override set` fully resolves it's input
594595 // before writing to settings.toml, so resolving here may not
595596 // be strictly necessary (could instead model as ToolchainName).
@@ -599,7 +600,7 @@ impl<'a> Cfg<'a> {
599600 let toolchain_name = ResolvableToolchainName :: try_from ( name) ?
600601 . resolve ( & get_default_host_triple ( settings, self . process ) ) ?;
601602 let override_cfg = toolchain_name. into ( ) ;
602- return Ok ( Some ( ( override_cfg, reason ) ) ) ;
603+ return Ok ( Some ( ( override_cfg, source ) ) ) ;
603604 }
604605
605606 // Then look for 'rust-toolchain' or 'rust-toolchain.toml'
@@ -683,9 +684,9 @@ impl<'a> Cfg<'a> {
683684 }
684685 }
685686
686- let reason = ActiveReason :: ToolchainFile ( toolchain_file) ;
687+ let source = ActiveSource :: ToolchainFile ( toolchain_file) ;
687688 let override_cfg = OverrideCfg :: from_file ( self , override_file) ?;
688- return Ok ( Some ( ( override_cfg, reason ) ) ) ;
689+ return Ok ( Some ( ( override_cfg, source ) ) ) ;
689690 }
690691
691692 dir = d. parent ( ) ;
@@ -779,8 +780,8 @@ impl<'a> Cfg<'a> {
779780 & self ,
780781 force_non_host : bool ,
781782 verbose : bool ,
782- ) -> Result < ( LocalToolchainName , ActiveReason ) > {
783- if let Some ( ( override_config, reason ) ) = self . find_override_config ( ) ? {
783+ ) -> Result < ( LocalToolchainName , ActiveSource ) > {
784+ if let Some ( ( override_config, source ) ) = self . find_override_config ( ) ? {
784785 let toolchain = override_config. clone ( ) . into_local_toolchain_name ( ) ;
785786 if let OverrideCfg :: Official {
786787 toolchain,
@@ -799,18 +800,18 @@ impl<'a> Cfg<'a> {
799800 )
800801 . await ?;
801802 } else {
802- Toolchain :: with_reason ( self , toolchain. clone ( ) , & reason ) ?;
803+ Toolchain :: with_source ( self , toolchain. clone ( ) , & source ) ?;
803804 }
804- Ok ( ( toolchain, reason ) )
805+ Ok ( ( toolchain, source ) )
805806 } else if let Some ( toolchain) = self . get_default ( ) ? {
806- let reason = ActiveReason :: Default ;
807+ let source = ActiveSource :: Default ;
807808 if let ToolchainName :: Official ( desc) = & toolchain {
808809 self . ensure_installed ( desc, vec ! [ ] , vec ! [ ] , None , force_non_host, verbose)
809810 . await ?;
810811 } else {
811- Toolchain :: with_reason ( self , toolchain. clone ( ) . into ( ) , & reason ) ?;
812+ Toolchain :: with_source ( self , toolchain. clone ( ) . into ( ) , & source ) ?;
812813 }
813- Ok ( ( toolchain. into ( ) , reason ) )
814+ Ok ( ( toolchain. into ( ) , source ) )
814815 } else {
815816 Err ( no_toolchain_error ( self . process ) )
816817 }
0 commit comments