Skip to content

feat(toolchain): support default toolchain aliases - #5071

Open
14elias wants to merge 1 commit into
rust-lang:mainfrom
14elias:feat/add_default
Open

14elias wants to merge 1 commit into
rust-lang:mainfrom
14elias:feat/add_default

Conversation

@14elias

@14elias 14elias commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Related to #5025.

this change Allows default to be used as a toolchain alias and resolve it to the configured default toolchain.
This makes default usable consistently across the supported override mechanisms, including +default, RUSTUP_TOOLCHAIN=default, directory overrides, and rust-toolchain files.
For example, when the configured default toolchain is stable: +default, RUSTUP_TOOLCHAIN=default all resolve to the configured stable toolchain.
A toolchain file containing:
[toolchain]
channel = "default"
also resolves to the configured default toolchain.

Tests

  • +default resolution.
  • RUSTUP_TOOLCHAIN=default.
  • rust-toolchain.toml using channel = "default".

Comment thread src/cli/rustup_mode.rs Outdated
Comment thread src/cli/rustup_mode.rs Outdated
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

Comment thread src/cli/self_update.rs Outdated
Some(ResolvableToolchainName::Official(t)) => Some(t),
// Default is custom, presumably from a prior install. Do nothing.
Some(ResolvableToolchainName::Custom(_)) => None,
// The configured default cannot itself be the default alias.

@rami3l rami3l Sep 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is redundant now.

View changes since the review

Comment thread src/toolchain/names.rs
}

impl Display for ToolchainAlias {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

@rami3l rami3l Sep 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest importing std::fmt.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the existing code uses this pattern that's why i used that but i can import std::fmt and change in all the places if you want.

Comment thread src/toolchain/names.rs Outdated
Comment on lines +87 to +91
if value == "default" {
Ok(Self::Default)
} else {
Err(InvalidName::ToolchainName(value.into()))
}

@rami3l rami3l Sep 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest using match instead of if here so that we can easily add more variants (with exhaustiveness check).

View changes since the review

Comment thread src/toolchain/names.rs
/// An alias for a toolchain name.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum ToolchainAlias {
Default,

@rami3l rami3l Sep 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding a docstring explaining the precise semantics of each variant.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

///Refers to rustup's configured default toolchain.
///Parsed from the literal string "default". is this docstring good at representing the variant

@rami3l rami3l Sep 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@14elias I think just keeping the first line would be fine. Also could you write your comments, PR descriptions etc in proper formatted markdown? It's not super easy to read to me in its current state.

Comment thread src/toolchain/names.rs Outdated
type Err = InvalidName;

fn from_str(value: &str) -> Result<Self, Self::Err> {
if let Ok(candidate) = validate_name(value)

@rami3l rami3l Sep 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check makes no sense because it overlaps with the latter check. Note that your aliases are a predetermined set of strings.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i kept validate_name() in ToolchainOverride::from_str() because it allow input +default/ as +stable/ . but if aliases should only accept exact names then checking if the value is alias is enough.

Comment thread src/config.rs Outdated
Comment on lines +35 to +72
impl ToolchainOverride<ResolvableToolchainName> {
pub fn resolve(self, cfg: &Cfg<'_>) -> anyhow::Result<ResolvableToolchainName> {
match self {
Self::Alias(ToolchainAlias::Default) => cfg
.get_default_resolvable()?
.ok_or_else(|| no_toolchain_error(cfg.process)),
Self::Explicit(r) => Ok(r),
}
}
}

impl ToolchainOverride<ResolvableLocalToolchainName> {
pub fn resolve(self, cfg: &Cfg<'_>) -> anyhow::Result<ResolvableLocalToolchainName> {
match self {
Self::Alias(ToolchainAlias::Default) => {
let default = cfg
.get_default_resolvable()?
.ok_or_else(|| no_toolchain_error(cfg.process))?;
Ok(ResolvableLocalToolchainName::Named(default))
}
Self::Explicit(r) => Ok(r),
}
}
}

impl ToolchainOverride<MaybeResolvableToolchainName> {
pub fn resolve(self, cfg: &Cfg<'_>) -> anyhow::Result<MaybeResolvableToolchainName> {
match self {
Self::Alias(ToolchainAlias::Default) => {
let default = cfg
.get_default_resolvable()?
.ok_or_else(|| anyhow::anyhow!("no default toolchain is configured"))?;
Ok(MaybeResolvableToolchainName::Some(default))
}
Self::Explicit(r) => Ok(r),
}
}
}

@rami3l rami3l Sep 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be able to replace all this with a single, generic impl block with an appropriate use of the From trait. Suggest adding the necessary From implementations if needed.

View changes since the review

Comment thread src/toolchain/names.rs Outdated

/// A wrapper for types that can be overridden by an alias.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum ToolchainOverride<T> {

@rami3l rami3l Sep 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the uses of this type are always of the form ToolchainOverride<xxxToolchain>, suggest renaming this to just Override.

View changes since the review

Comment thread src/toolchain/names.rs Outdated
/// A wrapper for types that can be overridden by an alias.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum ToolchainOverride<T> {
Alias(ToolchainAlias),

@rami3l rami3l Sep 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest using the same part of speech (preferably adjective) for all variants. In this case I'd suggest Aliased to mirror Explicit.

View changes since the review

Comment thread src/cli/rustup_mode.rs Outdated
match toolchain.to_owned() {
let toolchain = toolchain.resolve(cfg)?;

match toolchain {

@rami3l rami3l Sep 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest inlining this temporary variable toolchain.

View changes since the review

Comment thread src/cli/proxy_mode.rs Outdated
ActiveSource::CommandLine,
)),
Some(name) => {
let name = name.resolve(&cfg)?;

@rami3l rami3l Sep 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest inlining this temporary variable name.

View changes since the review

Comment thread src/cli/proxy_mode.rs
@@ -5,7 +5,7 @@
command::run_command_for_dir,

@rami3l rami3l Sep 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The category specified in the commit message is wrong. It should look more like feat(toolchain): or similar. Same thing for the title of this PR.

View changes since the review

Comment thread src/cli/proxy_mode.rs
@@ -1,2 +1,2 @@
use std::{path::PathBuf, process::ExitStatus, str::FromStr};

@rami3l rami3l Sep 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, if you have used LLM/agents to draft this PR, please properly disclose the fact in the PR description according to our contribution guidelines. Otherwise, I may close this PR without any prior warnings.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the confusion or inconvenience caused, but i did not used AI agent or LLM to write the code, or draft this PR description. i used LLM to brainstorm how to solve the problem specifically after you suggested me to create new data type instead of mixing the alias Default variant to the real tool chain variants and also i used github copilot to check if i applied ToolchainOverride consistently across the relevant functions and return types and i tested everything by myself, but i will add the tools i used for help when i update the PR description. thanks for checking.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i also used github copilot to help me with tests i mean the role is not like writing the tests it is just like discussing the edge cases and checking what i write and telling me to update the parts i have to modify and what i have to cover. that is how i use AI

@14elias 14elias changed the title test: support default toolchain aliases feat(toolchain): support default toolchain aliases Sep 14, 2026
@rustbot

rustbot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants