Skip to content

Commit f7aeab6

Browse files
author
Jon Gjengset
committed
Disallow path + toolchain options
1 parent 83f8b16 commit f7aeab6

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

src/config.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,15 @@ impl<'a> OverrideCfg<'a> {
9595
Ok(Self {
9696
toolchain: match (file.toolchain.channel, file.toolchain.path) {
9797
(Some(name), None) => Some(Toolchain::from(cfg, &name)?),
98-
(None, Some(path)) => Some(Toolchain::from_path(cfg, cfg_path, &path)?),
98+
(None, Some(path)) => {
99+
if file.toolchain.targets.is_some()
100+
|| file.toolchain.components.is_some()
101+
|| file.toolchain.profile.is_some()
102+
{
103+
return Err(ErrorKind::CannotSpecifyPathAndOptions(path.into()).into());
104+
}
105+
Some(Toolchain::from_path(cfg, cfg_path, &path)?)
106+
}
99107
(Some(channel), Some(path)) => {
100108
return Err(ErrorKind::CannotSpecifyChannelAndPath(channel, path.into()).into())
101109
}

src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ error_chain! {
192192
description("invalid toolchain path"),
193193
display("invalid toolchain path: '{}'", p.display())
194194
}
195+
CannotSpecifyPathAndOptions(path: PathBuf) {
196+
description("toolchain options are ignored for path toolchains"),
197+
display("toolchain options are ignored for path toolchain ({})", path.display())
198+
}
195199
CannotSpecifyChannelAndPath(channel: String, path: PathBuf) {
196200
description("cannot specify channel and path simultaneously"),
197201
display("cannot specify both channel ({}) and path ({}) simultaneously", channel, path.display())

tests/cli-rustup.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,54 @@ fn file_override_path_relative() {
14781478
});
14791479
}
14801480

1481+
#[test]
1482+
fn file_override_path_no_options() {
1483+
setup(&|config| {
1484+
// Make a plausible-looking toolchain
1485+
let cwd = config.current_dir();
1486+
let toolchain_path = cwd.join("ephemeral");
1487+
let toolchain_bin = toolchain_path.join("bin");
1488+
fs::create_dir_all(&toolchain_bin).unwrap();
1489+
1490+
let toolchain_file = cwd.join("rust-toolchain.toml");
1491+
raw::write_file(
1492+
&toolchain_file,
1493+
"[toolchain]\npath=\"ephemeral\"\ntargets=[\"dummy\"]",
1494+
)
1495+
.unwrap();
1496+
1497+
expect_err(
1498+
config,
1499+
&["rustc", "--version"],
1500+
"toolchain options are ignored for path toolchain (ephemeral)",
1501+
);
1502+
1503+
raw::write_file(
1504+
&toolchain_file,
1505+
"[toolchain]\npath=\"ephemeral\"\ncomponents=[\"dummy\"]",
1506+
)
1507+
.unwrap();
1508+
1509+
expect_err(
1510+
config,
1511+
&["rustc", "--version"],
1512+
"toolchain options are ignored for path toolchain (ephemeral)",
1513+
);
1514+
1515+
raw::write_file(
1516+
&toolchain_file,
1517+
"[toolchain]\npath=\"ephemeral\"\nprofile=\"minimal\"",
1518+
)
1519+
.unwrap();
1520+
1521+
expect_err(
1522+
config,
1523+
&["rustc", "--version"],
1524+
"toolchain options are ignored for path toolchain (ephemeral)",
1525+
);
1526+
});
1527+
}
1528+
14811529
#[test]
14821530
fn file_override_path_xor_channel() {
14831531
setup(&|config| {

0 commit comments

Comments
 (0)