Skip to content

Commit 61650b9

Browse files
committed
feat(config): warn user if auto-install is enabled
1 parent 50e98fb commit 61650b9

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

src/config.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use anyhow::{Context, Result, anyhow, bail};
88
use serde::Deserialize;
99
use thiserror::Error as ThisError;
1010
use tokio_stream::StreamExt;
11-
use tracing::trace;
11+
use tracing::{info, trace, warn};
1212

1313
use crate::dist::AutoInstallMode;
1414
use crate::{
@@ -387,12 +387,26 @@ impl<'a> Cfg<'a> {
387387
}
388388

389389
pub(crate) fn should_auto_install(&self) -> Result<bool> {
390-
if let Ok(mode) = self.process.var("RUSTUP_AUTO_INSTALL") {
391-
Ok(mode != "0")
392-
} else {
393-
self.settings_file
394-
.with(|s| Ok(s.auto_install != Some(AutoInstallMode::Disable)))
390+
let res = match self.process.var("RUSTUP_AUTO_INSTALL") {
391+
Ok(mode) => mode != "0",
392+
Err(_) => self
393+
.settings_file
394+
.with(|s| Ok(s.auto_install != Some(AutoInstallMode::Disable)))?,
395+
};
396+
if res
397+
// We also need to suppress this warning if we're deep inside a recursive call.
398+
&& matches!(
399+
self.process.var("RUST_RECURSION_COUNT").as_deref(),
400+
Err(_) | Ok("0"),
401+
)
402+
{
403+
warn!("auto-install is enabled, active toolchain will be installed if absent");
404+
warn!("this behavior is deprecated and will be removed in a future version");
405+
info!(
406+
"you may opt out now with `RUSTUP_AUTO_INSTALL=0` or `rustup set auto-install disable`"
407+
);
395408
}
409+
Ok(res)
396410
}
397411

398412
// Returns a profile, if one exists in the settings file.

tests/suite/cli_misc.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff 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 behavior is deprecated and will be removed in a future version
1771+
info: you may opt out now with `RUSTUP_AUTO_INSTALL=0` or `rustup set auto-install disable`
1772+
...
1773+
"#]])
1774+
.is_ok();
1775+
}

0 commit comments

Comments
 (0)