Skip to content

Commit 8f619f8

Browse files
committed
feat(config): warn user if auto-install is enabled
1 parent 5563bf9 commit 8f619f8

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

src/config.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff 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.

tests/suite/cli_misc.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,3 +1749,26 @@ info: falling back to "[EXTERN_PATH]"
17491749
"#]])
17501750
.is_ok();
17511751
}
1752+
1753+
#[tokio::test]
1754+
async fn warn_auto_install() {
1755+
let cx = CliTestContext::new(Scenario::SimpleV2).await;
1756+
cx.config
1757+
.expect_with_env(
1758+
["rustc", "--version"],
1759+
[("RUSTUP_TOOLCHAIN", "stable"), ("RUSTUP_AUTO_INSTALL", "1")],
1760+
)
1761+
.await
1762+
.with_stdout(snapbox::str![[r#"
1763+
1.1.0 (hash-stable-1.1.0)
1764+
1765+
"#]])
1766+
.with_stderr(snapbox::str![[r#"
1767+
...
1768+
warn: auto-install is enabled, active toolchain will be installed if absent
1769+
warn: this might cause rustup commands to take longer time to finish than expected
1770+
info: you may opt out with `RUSTUP_AUTO_INSTALL=0` or `rustup set auto-install disable`
1771+
...
1772+
"#]])
1773+
.is_ok();
1774+
}

0 commit comments

Comments
 (0)