Skip to content

Commit 0cde1e9

Browse files
committed
refactor(toolchain)!: postpone eval of install_if_missing in Toolchain::from_local()
1 parent 8ab1b84 commit 0cde1e9

3 files changed

Lines changed: 7 additions & 10 deletions

File tree

src/cli/rustup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ async fn run(
10671067
install: bool,
10681068
) -> Result<ExitStatus> {
10691069
let toolchain = toolchain.resolve(&cfg.get_default_host_triple()?)?;
1070-
let toolchain = Toolchain::from_local(toolchain, install, cfg).await?;
1070+
let toolchain = Toolchain::from_local(toolchain, || Ok(install), cfg).await?;
10711071
let cmd = toolchain.command(&command[0])?;
10721072
command::run_command_for_dir(cmd, &command[0], &command[1..])
10731073
}

src/config.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -717,13 +717,10 @@ impl<'a> Cfg<'a> {
717717
name: Option<(LocalToolchainName, ActiveSource)>,
718718
) -> Result<(Toolchain<'_>, ActiveSource)> {
719719
match name {
720-
Some((tc, source)) => {
721-
let install_if_missing = self.should_auto_install()?;
722-
Ok((
723-
Toolchain::from_local(tc, install_if_missing, self).await?,
724-
source,
725-
))
726-
}
720+
Some((tc, src)) => Ok((
721+
Toolchain::from_local(tc, || self.should_auto_install(), self).await?,
722+
src,
723+
)),
727724
None => {
728725
let (tc, source) = self
729726
.maybe_ensure_active_toolchain(None)

src/toolchain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ pub(crate) struct Toolchain<'a> {
5252
impl<'a> Toolchain<'a> {
5353
pub(crate) async fn from_local(
5454
name: LocalToolchainName,
55-
install_if_missing: bool,
55+
install_if_missing: impl Fn() -> anyhow::Result<bool>,
5656
cfg: &'a Cfg<'a>,
5757
) -> anyhow::Result<Toolchain<'a>> {
5858
match Self::new(cfg, name) {
5959
Ok(tc) => Ok(tc),
6060
Err(RustupError::ToolchainNotInstalled {
6161
name: ToolchainName::Official(desc),
6262
..
63-
}) if install_if_missing => {
63+
}) if install_if_missing()? => {
6464
let options = DistOptions::new(&[], &[], &desc, cfg.get_profile()?, true, cfg)?;
6565
Ok(DistributableToolchain::install(options).await?.1.toolchain)
6666
}

0 commit comments

Comments
 (0)