diff --git a/src/dist/manifest.rs b/src/dist/manifest.rs index e3146fe09d..e91f8ac178 100644 --- a/src/dist/manifest.rs +++ b/src/dist/manifest.rs @@ -498,19 +498,11 @@ impl Component { distributable: &DistributableToolchain<'_>, fallback_target: Option<&TargetTriple>, ) -> Result { + let manifest = distributable.get_manifest()?; for component_status in distributable.components()? { - let short_name = component_status.component.short_name_in_manifest(); - let target = component_status.component.target.as_ref(); - - if name.starts_with(short_name) - && target.is_some() - && name == format!("{}-{}", short_name, target.unwrap()) - { - return Ok(Component::new( - short_name.to_string(), - target.cloned(), - false, - )); + let component = component_status.component; + if name == component.name_in_manifest() || name == component.name(&manifest) { + return Ok(component); } } diff --git a/tests/suite/cli_rustup.rs b/tests/suite/cli_rustup.rs index 5eb5d3dd4b..b9b6003aae 100644 --- a/tests/suite/cli_rustup.rs +++ b/tests/suite/cli_rustup.rs @@ -1542,6 +1542,38 @@ async fn add_component_by_target_triple() { assert!(cx.config.rustupdir.has(path)); } +#[tokio::test] +async fn add_component_by_target_triple_renamed_from() { + let mut cx = CliTestContext::new(Scenario::SimpleV2).await; + cx.config.expect_ok(&["rustup", "default", "nightly"]).await; + cx.config + .expect_ok(&["rustup", "component", "add", for_host!("rls-{}")]) + .await; + cx.config + .expect_ok_contains( + &["rustup", "component", "list", "--installed"], + for_host!("rls-{}"), + "", + ) + .await; +} + +#[tokio::test] +async fn add_component_by_target_triple_renamed_to() { + let mut cx = CliTestContext::new(Scenario::SimpleV2).await; + cx.config.expect_ok(&["rustup", "default", "nightly"]).await; + cx.config + .expect_ok(&["rustup", "component", "add", for_host!("rls-preview-{}")]) + .await; + cx.config + .expect_ok_contains( + &["rustup", "component", "list", "--installed"], + for_host!("rls-{}"), + "", + ) + .await; +} + #[tokio::test] async fn fail_invalid_component_name() { let mut cx = CliTestContext::new(Scenario::SimpleV2).await;