Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/toolchain/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ pub enum InvalidName {
ToolchainPath(String),
#[error("invalid toolchain name '{0}'")]
ToolchainName(String),
#[error("invalid toolchain name '+{0}'; valid toolchain names do not start with '+'")]
PlusPrefix(String),
}

macro_rules! from_variant {
Expand Down Expand Up @@ -117,6 +119,9 @@ macro_rules! try_from_str {

/// Common validate rules for all sorts of toolchain names
fn validate(candidate: &str) -> Result<&str, InvalidName> {
if let Some(without_plus) = candidate.strip_prefix('+') {
return Err(InvalidName::PlusPrefix(without_plus.to_string()));
}
let normalized_name = candidate.trim_end_matches('/');
if normalized_name.is_empty() {
Err(InvalidName::ToolchainName(candidate.into()))
Expand Down Expand Up @@ -501,8 +506,9 @@ mod tests {

prop_compose! {
fn arb_custom_name()
(s in r"[^\\/]+") -> String {
(s in r"[^\\/+][^\\/]*") -> String {
// perhaps need to filter 'none' and partial toolchains - but they won't typically be generated anyway.
// Also filter '+' prefix as that's reserved for +toolchain syntax.
s
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/suite/cli_rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2222,6 +2222,25 @@ error:[..] relative path toolchain '[..]/toolchains/nightly-[HOST_TRIPLE]'
.is_err();
}

#[tokio::test]
async fn run_with_plus_prefix_fails_with_helpful_message() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "default", "stable"])
.await
.is_ok();

cx.config
.expect(["rustup", "run", "+stable", "cargo", "check"])
.await
.with_stderr(snapbox::str![[r#"
...
error:[..] invalid toolchain name '+stable'; valid toolchain names do not start with '+'
...
"#]])
.is_err();
}

#[tokio::test]
async fn plus_override_abspath_is_supported() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
Expand Down