Skip to content

Commit 5a30260

Browse files
committed
refactor(toolchain)!: postpone eval of install_if_missing in Toolchain::from_local()
1 parent a051909 commit 5a30260

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

src/cli/rustup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ async fn run(
10231023
install: bool,
10241024
) -> Result<ExitStatus> {
10251025
let toolchain = toolchain.resolve(&cfg.get_default_host_triple()?)?;
1026-
let toolchain = Toolchain::from_local(toolchain, install, cfg).await?;
1026+
let toolchain = Toolchain::from_local(toolchain, || Ok(install), cfg).await?;
10271027
let cmd = toolchain.command(&command[0])?;
10281028
command::run_command_for_dir(cmd, &command[0], &command[1..])
10291029
}

src/config.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,10 +746,7 @@ impl<'a> Cfg<'a> {
746746

747747
async fn local_toolchain(&self, name: Option<LocalToolchainName>) -> Result<Toolchain<'_>> {
748748
match name {
749-
Some(tc) => {
750-
let install_if_missing = self.should_auto_install()?;
751-
Toolchain::from_local(tc, install_if_missing, self).await
752-
}
749+
Some(tc) => Toolchain::from_local(tc, || self.should_auto_install(), self).await,
753750
None => {
754751
let tc = self
755752
.maybe_ensure_active_toolchain(None)

src/toolchain.rs

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

0 commit comments

Comments
 (0)