Skip to content

Commit 7e8d23a

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

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/toolchain.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::{
1515
use anyhow::{Context, anyhow, bail};
1616
use fs_at::OpenOptions;
1717
use same_file::is_same_file;
18-
use tracing::info;
18+
use tracing::{info, warn};
1919
use url::Url;
2020
use wait_timeout::ChildExt;
2121

@@ -61,6 +61,18 @@ impl<'a> Toolchain<'a> {
6161
name: ToolchainName::Official(desc),
6262
..
6363
}) if install_if_missing()? => {
64+
// Emit a warning about auto-installation if we aren't deep inside a recursive call.
65+
let recursions = cfg.process.var("RUST_RECURSION_COUNT");
66+
if !recursions.is_ok_and(|it| it != "0") {
67+
warn!("auto-install is enabled, active toolchain will be installed if absent");
68+
warn!(
69+
"this might cause rustup commands to take longer time to finish than expected"
70+
);
71+
info!(
72+
"you may opt out with `RUSTUP_AUTO_INSTALL=0` or `rustup set auto-install disable`"
73+
);
74+
}
75+
6476
let options = DistOptions::new(&[], &[], &desc, cfg.get_profile()?, true, cfg)?;
6577
Ok(DistributableToolchain::install(options).await?.1.toolchain)
6678
}

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)