File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -384,12 +384,26 @@ impl<'a> Cfg<'a> {
384384 return Ok ( false ) ;
385385 }
386386
387- if let Ok ( mode) = self . process . var ( "RUSTUP_AUTO_INSTALL" ) {
388- Ok ( mode != "0" )
389- } else {
390- self . settings_file
391- . with ( |s| Ok ( s. auto_install != Some ( AutoInstallMode :: Disable ) ) )
387+ let should_auto = match self . process . var ( "RUSTUP_AUTO_INSTALL" ) {
388+ Ok ( mode) => mode != "0" ,
389+ Err ( _) => self
390+ . settings_file
391+ . with ( |s| Ok ( s. auto_install != Some ( AutoInstallMode :: Disable ) ) ) ?,
392+ } ;
393+ if !should_auto {
394+ return Ok ( false ) ;
392395 }
396+
397+ // We also need to suppress this warning if we're deep inside a recursive call.
398+ let recursions = self . process . var ( "RUST_RECURSION_COUNT" ) ;
399+ if recursions. is_ok_and ( |it| it != "0" ) {
400+ return Ok ( true ) ;
401+ }
402+
403+ warn ! ( "auto-install is enabled, active toolchain will be installed if absent" ) ;
404+ warn ! ( "this might cause rustup commands to take longer time to finish than expected" ) ;
405+ info ! ( "you may opt out with `RUSTUP_AUTO_INSTALL=0` or `rustup set auto-install disable`" ) ;
406+ Ok ( true )
393407 }
394408
395409 // Returns a profile, if one exists in the settings file.
Original file line number Diff line number Diff line change @@ -314,6 +314,9 @@ impl Config {
314314 "/bogus-config-file.toml" ,
315315 ) ;
316316
317+ // Clear current recursion count to avoid messing up related logic
318+ cmd. env ( "RUST_RECURSION_COUNT" , "" ) ;
319+
317320 // Pass `RUSTUP_CI` over to the test process in case it is required downstream
318321 if let Some ( ci) = env:: var_os ( "RUSTUP_CI" ) {
319322 cmd. env ( "RUSTUP_CI" , ci) ;
Original file line number Diff line number Diff line change @@ -1746,3 +1746,30 @@ info: falling back to "[EXTERN_PATH]"
17461746"# ] ] )
17471747 . is_ok ( ) ;
17481748}
1749+
1750+ #[ tokio:: test]
1751+ async fn warn_auto_install ( ) {
1752+ let cx = CliTestContext :: new ( Scenario :: SimpleV2 ) . await ;
1753+ cx. config
1754+ . expect_with_env (
1755+ [ "rustc" , "--version" ] ,
1756+ [
1757+ ( "RUSTUP_TOOLCHAIN" , "stable" ) ,
1758+ ( "RUSTUP_AUTO_INSTALL" , "1" ) ,
1759+ ( "RUST_RECURSION_COUNT" , "" ) ,
1760+ ] ,
1761+ )
1762+ . await
1763+ . with_stdout ( snapbox:: str![ [ r#"
1764+ 1.1.0 (hash-stable-1.1.0)
1765+
1766+ "# ] ] )
1767+ . with_stderr ( snapbox:: str![ [ r#"
1768+ ...
1769+ warn: auto-install is enabled, active toolchain will be installed if absent
1770+ warn: this might cause rustup commands to take longer time to finish than expected
1771+ info: you may opt out with `RUSTUP_AUTO_INSTALL=0` or `rustup set auto-install disable`
1772+ ...
1773+ "# ] ] )
1774+ . is_ok ( ) ;
1775+ }
You can’t perform that action at this time.
0 commit comments