diff --git a/src/config.rs b/src/config.rs index 88aa367fb4..00f4b6bed8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -472,14 +472,18 @@ impl Cfg { if let Ok(s) = utils::read_file("toolchain file", &toolchain_file) { if let Some(s) = s.lines().next() { let toolchain_name = s.trim(); - dist::validate_channel_name(&toolchain_name).chain_err(|| { - format!( - "invalid channel name '{}' in '{}'", - toolchain_name, - toolchain_file.display() - ) - })?; - + let all_toolchains = self.list_toolchains()?; + if !all_toolchains.iter().any(|s| s == toolchain_name) { + // The given name is not resolvable as a toolchain, so + // instead check it's plausible for installation later + dist::validate_channel_name(&toolchain_name).chain_err(|| { + format!( + "invalid channel name '{}' in '{}'", + toolchain_name, + toolchain_file.display() + ) + })?; + } let reason = OverrideReason::ToolchainFile(toolchain_file); return Ok(Some((toolchain_name.to_string(), reason))); } diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index 7151a16a0e..246097d5dd 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -1534,6 +1534,36 @@ fn bad_file_override() { }); } +#[test] +fn valid_override_settings() { + setup(&|config| { + let cwd = config.current_dir(); + let toolchain_file = cwd.join("rust-toolchain"); + expect_ok(config, &["rustup", "default", "nightly"]); + raw::write_file(&toolchain_file, "nightly").unwrap(); + expect_ok(config, &["rustc", "--version"]); + raw::write_file(&toolchain_file, for_host!("nightly-{}")).unwrap(); + expect_ok(config, &["rustc", "--version"]); + let fullpath = config + .rustupdir + .clone() + .join("toolchains") + .join(for_host!("nightly-{}")); + expect_ok( + config, + &[ + "rustup", + "toolchain", + "link", + "system", + &format!("{}", fullpath.display()), + ], + ); + raw::write_file(&toolchain_file, "system").unwrap(); + expect_ok(config, &["rustc", "--version"]); + }) +} + #[test] fn file_override_with_target_info() { setup(&|config| {