Skip to content

rustup default no longer exits with 1 with no default toolchain is set #4140

Closed
@weihanglo

Description

@weihanglo

Verification

Problem

(Edited by @rami3l to better reflect the original issue)

Coming from https://internals.rust-lang.org/t/seeking-beta-testers-for-rustup-v1-28-0/22060.

With rustup v1.27.1, the following shell snippet can be used to force the installation of the default toolchain, or fall back on stable when none is present:

rustup default || rustup default stable

When testing out the upcoming 1.28 release, however, I found that rustup default is returning 0 even there's no such thing as the default toolchain, resulting in an unchanged default toolchain state.

I've noticed the suggestion provided in the post:

rustup show active-toolchain || rustup toolchain install

... but it doesn't really help with the use case above, since regardless in 1.27.1, the current stable branch (1.28-beta), it seems to always exit with code 0.

  • 1.27.1

    rustup/src/cli/rustup_mode.rs

    Lines 1227 to 1257 in 54dd3d0

    fn show_active_toolchain(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
    let verbose = m.get_flag("verbose");
    let cwd = utils::current_dir()?;
    match cfg.find_or_install_override_toolchain_or_default(&cwd) {
    Err(e) => {
    let root_cause = e.root_cause();
    if let Some(RustupError::ToolchainNotSelected) =
    root_cause.downcast_ref::<RustupError>()
    {
    } else {
    return Err(e);
    }
    }
    Ok((toolchain, reason)) => {
    if let Some(reason) = reason {
    writeln!(
    process().stdout().lock(),
    "{} ({})",
    toolchain.name(),
    reason
    )?;
    } else {
    writeln!(process().stdout().lock(), "{} (default)", toolchain.name())?;
    }
    if verbose {
    writeln!(process().stdout().lock(), "{}", toolchain.rustc_version())?;
    }
    }
    }
    Ok(utils::ExitCode(0))
    }
  • stable

    rustup/src/cli/rustup_mode.rs

    Lines 1100 to 1105 in 7ccf717

    None => writeln!(
    cfg.process.stdout().lock(),
    "There isn't an active toolchain"
    )?,
    }
    Ok(utils::ExitCode(0))

Steps

  1. rustup default none
  2. rustup default || rustup default stable

Possible Solution(s)

Should we find another workaround?

Notes

No response

Rustup version

* rustup 1.27.1 (1980-01-01)
* rustup 1.28.0 (7ccf717e6e1aee46f65cc6fea4132a3f0e37593b)

Installed toolchains

rustup 1.27.1

installed toolchains
--------------------

error: no default toolchain configured

rustup 1.28.0

installed toolchains
--------------------

active toolchain
----------------
no active toolchain

OS version

Both Darwin and Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions