-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(toolchain): support default toolchain aliases #5071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,65 @@ pub enum InvalidName { | |
| DashPrefix(String), | ||
| } | ||
|
|
||
| /// An alias for a toolchain name. | ||
| #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
| pub enum ToolchainAlias { | ||
| ///Refers to rustup's configured default toolchain | ||
| Default, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest adding a docstring explaining the precise semantics of each variant.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ///Refers to rustup's configured default toolchain.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
|
|
||
| impl FromStr for ToolchainAlias { | ||
| type Err = InvalidName; | ||
|
|
||
| fn from_str(value: &str) -> Result<Self, Self::Err> { | ||
| match value { | ||
| "default" => Ok(Self::Default), | ||
| _ => Err(InvalidName::ToolchainName(value.into())), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Display for ToolchainAlias { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest importing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| match self { | ||
| Self::Default => write!(f, "default"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// A wrapper for types that can be overridden by an alias. | ||
| #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
| pub enum Override<T> { | ||
| Aliased(ToolchainAlias), | ||
| Explicit(T), | ||
| } | ||
|
|
||
| impl<T: FromStr> FromStr for Override<T> | ||
| where | ||
| T::Err: Into<InvalidName>, | ||
| { | ||
| type Err = InvalidName; | ||
|
|
||
| fn from_str(value: &str) -> Result<Self, Self::Err> { | ||
| if let Ok(alias) = ToolchainAlias::from_str(value) { | ||
| return Ok(Self::Aliased(alias)); | ||
| } | ||
| match T::from_str(value) { | ||
| Ok(t) => Ok(Self::Explicit(t)), | ||
| Err(e) => Err(e.into()), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<T: Display> Display for Override<T> { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| match self { | ||
| Self::Aliased(a) => write!(f, "{a}"), | ||
| Self::Explicit(t) => write!(f, "{t}"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// A toolchain name from user input. | ||
| #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
| pub(crate) enum ResolvableToolchainName { | ||
|
|
@@ -155,6 +214,12 @@ impl Display for MaybeResolvableToolchainName { | |
| } | ||
| } | ||
|
|
||
| impl From<ResolvableToolchainName> for MaybeResolvableToolchainName { | ||
| fn from(value: ResolvableToolchainName) -> Self { | ||
| Self::Some(value) | ||
| } | ||
| } | ||
|
|
||
| /// ResolvableToolchainName + none, for overriding default-has-a-value | ||
| /// situations in the CLI with an official toolchain name or none | ||
| #[derive(Debug, Clone)] | ||
|
|
@@ -293,6 +358,12 @@ impl Display for ResolvableLocalToolchainName { | |
| } | ||
| } | ||
|
|
||
| impl From<ResolvableToolchainName> for ResolvableLocalToolchainName { | ||
| fn from(value: ResolvableToolchainName) -> Self { | ||
| Self::Named(value) | ||
| } | ||
| } | ||
|
|
||
| /// LocalToolchainName can be used in calls to Cfg that alter configuration, | ||
| /// like setting overrides, or that depend on configuration, like calculating | ||
| /// the toolchain directory. It is not used to model the RUSTUP_TOOLCHAIN | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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