diff --git a/src/config.rs b/src/config.rs index 7796849247..203bed1da3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -457,6 +457,10 @@ impl Cfg { })?; } + if name.is_empty() { + anyhow::bail!("toolchain names must not be empty"); + } + Toolchain::from(self, name) } diff --git a/tests/cli-v2.rs b/tests/cli-v2.rs index ba034aa946..64baa480e8 100644 --- a/tests/cli-v2.rs +++ b/tests/cli-v2.rs @@ -842,6 +842,19 @@ fn add_target_custom_toolchain() { }); } +#[test] +fn cannot_add_empty_named_custom_toolchain() { + setup(&|config| { + let path = config.customdir.join("custom-1"); + let path = path.to_string_lossy(); + expect_err( + config, + &["rustup", "toolchain", "link", "", &path], + "toolchain names must not be empty", + ); + }); +} + #[test] fn add_target_again() { setup(&|config| {