1- use std:: { path:: PathBuf , process:: ExitStatus } ;
1+ use std:: {
2+ path:: PathBuf ,
3+ process:: { Command , ExitStatus } ,
4+ } ;
25
36use anyhow:: Result ;
47
@@ -7,7 +10,7 @@ use crate::{
710 command:: run_command_for_dir,
811 config:: ActiveReason ,
912 process:: Process ,
10- toolchain:: { ResolvableLocalToolchainName , maybe_set_env_source } ,
13+ toolchain:: ResolvableLocalToolchainName ,
1114} ;
1215
1316#[ tracing:: instrument( level = "trace" , skip( process) ) ]
@@ -36,8 +39,23 @@ pub async fn main(arg0: &str, current_dir: PathBuf, process: &Process) -> Result
3639 let cfg = set_globals ( current_dir, true , process) ?;
3740 let toolchain = cfg. resolve_local_toolchain ( toolchain) . await ?;
3841 let mut cmd = toolchain. command ( arg0) ?;
39- if toolchain_specified {
40- maybe_set_env_source ( & mut cmd, || Some ( ActiveReason :: CommandLine ) ) ;
41- }
42+ set_env_source (
43+ & mut cmd,
44+ if toolchain_specified {
45+ Some ( ActiveReason :: CommandLine )
46+ } else if let Ok ( Some ( ( _, reason) ) ) = cfg. active_toolchain ( ) {
47+ Some ( reason)
48+ } else {
49+ None
50+ } ,
51+ ) ;
4252 run_command_for_dir ( cmd, arg0, & cmd_args)
4353}
54+
55+ /// Set the `RUSTUP_TOOLCHAIN_SOURCE` environment variable to indicate how the toolchain was
56+ /// determined.
57+ fn set_env_source ( cmd : & mut Command , reason : Option < ActiveReason > ) {
58+ if let Some ( reason) = reason {
59+ cmd. env ( "RUSTUP_TOOLCHAIN_SOURCE" , reason. to_source ( ) ) ;
60+ }
61+ }
0 commit comments