Skip to content

Commit c143541

Browse files
committed
Fallback to wildcard component
1 parent 217afec commit c143541

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/rustup/toolchain.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ impl<'a> Toolchain<'a> {
466466
self.bare_add_component(component)
467467
}
468468

469-
fn bare_add_component(&self, component: Component) -> Result<()> {
469+
fn bare_add_component(&self, mut component: Component) -> Result<()> {
470470
if !self.exists() {
471471
return Err(ErrorKind::ToolchainNotInstalled(self.name.to_owned()).into());
472472
}
@@ -490,7 +490,12 @@ impl<'a> Toolchain<'a> {
490490
}
491491

492492
if !targ_pkg.extensions.contains(&component) {
493-
return Err(ErrorKind::UnknownComponent(self.name.to_string(), component).into());
493+
let wildcard_component = Component { target: None, ..component.clone() };
494+
if targ_pkg.extensions.contains(&wildcard_component) {
495+
component = wildcard_component;
496+
} else {
497+
return Err(ErrorKind::UnknownComponent(self.name.to_string(), component).into());
498+
}
494499
}
495500

496501
let changes = Changes {
@@ -509,7 +514,7 @@ impl<'a> Toolchain<'a> {
509514
}
510515
}
511516

512-
pub fn remove_component(&self, component: Component) -> Result<()> {
517+
pub fn remove_component(&self, mut component: Component) -> Result<()> {
513518
if !self.exists() {
514519
return Err(ErrorKind::ToolchainNotInstalled(self.name.to_owned()).into());
515520
}
@@ -534,7 +539,12 @@ impl<'a> Toolchain<'a> {
534539

535540
let dist_config = try!(manifestation.read_config()).unwrap();
536541
if !dist_config.components.contains(&component) {
537-
return Err(ErrorKind::UnknownComponent(self.name.to_string(), component).into());
542+
let wildcard_component = Component { target: None, ..component.clone() };
543+
if dist_config.components.contains(&wildcard_component) {
544+
component = wildcard_component;
545+
} else {
546+
return Err(ErrorKind::UnknownComponent(self.name.to_string(), component).into());
547+
}
538548
}
539549

540550
let changes = Changes {

tests/cli-rustup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ fn src_component_smoke_test() {
524524
setup(&|config| {
525525
expect_ok(config, &["rustup", "default", "stable"]);
526526
expect_ok(config, &["rustup", "component", "add", "rust-src"]);
527-
let path = format!("toolchains/{}/lib/rustlib/src/rust-src/foo.rs",
527+
let path = format!("toolchains/stable-{}/lib/rustlib/src/rust-src/foo.rs",
528528
this_host_triple());
529529
let path = config.rustupdir.join(path);
530530
assert!(path.exists());

0 commit comments

Comments
 (0)