Conversation
7b83b06 to
d168934
Compare
This comment has been minimized.
This comment has been minimized.
d168934 to
8982db1
Compare
This comment has been minimized.
This comment has been minimized.
8982db1 to
de81ab2
Compare
| 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. |
There was a problem hiding this comment.
I think this change is redundant now.
| } | ||
|
|
||
| impl Display for ToolchainAlias { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
There was a problem hiding this comment.
Suggest importing std::fmt.
There was a problem hiding this comment.
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.
| if value == "default" { | ||
| Ok(Self::Default) | ||
| } else { | ||
| Err(InvalidName::ToolchainName(value.into())) | ||
| } |
There was a problem hiding this comment.
Suggest using match instead of if here so that we can easily add more variants (with exhaustiveness check).
| /// An alias for a toolchain name. | ||
| #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
| pub enum ToolchainAlias { | ||
| Default, |
There was a problem hiding this comment.
Suggest adding a docstring explaining the precise semantics of each variant.
There was a problem hiding this comment.
///Refers to rustup's configured default toolchain.
///Parsed from the literal string "default". is this docstring good at representing the variant
There was a problem hiding this comment.
@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.
| type Err = InvalidName; | ||
|
|
||
| fn from_str(value: &str) -> Result<Self, Self::Err> { | ||
| if let Ok(candidate) = validate_name(value) |
There was a problem hiding this comment.
This check makes no sense because it overlaps with the latter check. Note that your aliases are a predetermined set of strings.
There was a problem hiding this comment.
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.
| 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), | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
|
|
||
| /// A wrapper for types that can be overridden by an alias. | ||
| #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
| pub enum ToolchainOverride<T> { |
There was a problem hiding this comment.
Since the uses of this type are always of the form ToolchainOverride<xxxToolchain>, suggest renaming this to just Override.
| /// A wrapper for types that can be overridden by an alias. | ||
| #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
| pub enum ToolchainOverride<T> { | ||
| Alias(ToolchainAlias), |
There was a problem hiding this comment.
Suggest using the same part of speech (preferably adjective) for all variants. In this case I'd suggest Aliased to mirror Explicit.
| match toolchain.to_owned() { | ||
| let toolchain = toolchain.resolve(cfg)?; | ||
|
|
||
| match toolchain { |
There was a problem hiding this comment.
Suggest inlining this temporary variable toolchain.
| ActiveSource::CommandLine, | ||
| )), | ||
| Some(name) => { | ||
| let name = name.resolve(&cfg)?; |
There was a problem hiding this comment.
Suggest inlining this temporary variable name.
| @@ -5,7 +5,7 @@ | |||
| command::run_command_for_dir, | |||
There was a problem hiding this comment.
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.
| @@ -1,2 +1,2 @@ | |||
| use std::{path::PathBuf, process::ExitStatus, str::FromStr}; | |||
|
|
|||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
de81ab2 to
802fa8e
Compare
|
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. |
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