From 2b1db8573877825208dea26f75617dfb389b810a Mon Sep 17 00:00:00 2001 From: rami3l Date: Mon, 23 Nov 2026 11:23:41 +0100 Subject: [PATCH 1/5] refactor(dist): extract `Component::is_std()` --- src/cli/completions.rs | 2 +- src/cli/rustup_mode.rs | 7 +++---- src/dist/manifest.rs | 5 +++++ src/toolchain/channels.rs | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/cli/completions.rs b/src/cli/completions.rs index 0b494f3254..c5240019ef 100644 --- a/src/cli/completions.rs +++ b/src/cli/completions.rs @@ -37,7 +37,7 @@ pub(super) fn rustup_command(cfg: &Cfg<'_>, args: &[impl AsRef]) -> clap: .ok()? .into_iter() .filter_map(|c| { - (c.component.short_name() == "rust-std" && c.available) + (c.component.is_std() && c.available) .then(|| c.component.target.map(|t| t.to_string()))? }) .collect::>(), diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index f37d6b29c6..7b142f7d8d 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -1367,7 +1367,7 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> anyhow::Result { .components()? .into_iter() .filter_map(|c| { - (c.installed && c.component.short_name() == "rust-std") + (c.installed && c.component.is_std()) .then(|| c.component.target.expect("rust-std should have a target")) }) .collect(), @@ -1442,7 +1442,7 @@ async fn target_list( if let Ok(distributable) = ChannelToolchain::from_partial(toolchain.clone(), cfg).await { common::list_items( distributable.components()?.into_iter().filter_map(|c| { - if c.component.short_name() == "rust-std" && c.available { + if c.component.is_std() && c.available { c.component.target.map(|target| (target, c.installed)) } else { None @@ -1490,8 +1490,7 @@ async fn target_add( if all { distributable .add_components(distributable.components()?.into_iter().filter_map(|c| { - (c.available && !c.installed && c.component.short_name() == "rust-std") - .then_some(Ok(c.component)) + (c.available && !c.installed && c.component.is_std()).then_some(Ok(c.component)) })) .await?; diff --git a/src/dist/manifest.rs b/src/dist/manifest.rs index 7d5bfd2af7..e68daf2cbb 100644 --- a/src/dist/manifest.rs +++ b/src/dist/manifest.rs @@ -593,6 +593,11 @@ impl Component { &self.pkg } + /// Returns whether this component is a Rust standard library component. + pub fn is_std(&self) -> bool { + self.short_name() == "rust-std" + } + /// Returns the [`Component`]'s name **after** renaming, including the target if present. /// For the short name before renaming, see [`Manifest::name()`]. pub(crate) fn name(&self) -> String { diff --git a/src/toolchain/channels.rs b/src/toolchain/channels.rs index e6da19cb54..943fe15406 100644 --- a/src/toolchain/channels.rs +++ b/src/toolchain/channels.rs @@ -196,7 +196,7 @@ impl<'a> ChannelToolchain<'a> { let wanted_targets = targets.iter().all(|name| { installed_components .iter() - .filter(|c| c.component.short_name() == "rust-std") + .filter(|c| c.component.is_std()) .any(|status| { let ctarg = status.component.target(); (ctarg == *name) && status.installed From d6fb337f49831bc863e32708c6f134dcc88c8f63 Mon Sep 17 00:00:00 2001 From: rami3l <33851577+rami3l@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:54:46 +0000 Subject: [PATCH 2/5] test(cli): snapshot the current `rustup toolchain pin` output with an extra target Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- tests/suite/cli_rustup.rs | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/suite/cli_rustup.rs b/tests/suite/cli_rustup.rs index 47a0c4f358..fa2f574cce 100644 --- a/tests/suite/cli_rustup.rs +++ b/tests/suite/cli_rustup.rs @@ -5145,6 +5145,60 @@ components = ["cargo", "rust-docs", "rust-std", "rustc"] ); } +#[tokio::test] +async fn pin_default_with_extra_target() { + let cx = CliTestContext::new(Scenario::SimpleV2).await; + + let mut toml_redactions = snapbox::Redactions::new(); + toml_redactions + .insert("[CROSS_ARCH_I]", CROSS_ARCH1) + .unwrap(); + let toml_assert = snapbox::Assert::new() + .action_env(snapbox::assert::DEFAULT_ACTION_ENV) + .redact_with(toml_redactions); + + cx.config + .expect(["rustup", "default", "beta"]) + .await + .is_ok(); + cx.config + .expect(["rustup", "target", "add", CROSS_ARCH1]) + .await + .is_ok(); + + cx.config + .expect(["rustup", "toolchain", "pin"]) + .await + .is_ok(); + + let toolchain_file = &cx.config.current_dir().join("rust-toolchain.toml"); + toml_assert.eq( + fs::read_to_string(toolchain_file).unwrap(), + snapbox::str![[r#" +... +[toolchain] +channel = "beta" +components = ["cargo", "rust-docs", "rust-std", "rust-std-[CROSS_ARCH_I]", "rustc"] + +"#]], + ); + + cx.config + .expect(["rustup", "toolchain", "uninstall", "beta"]) + .await + .is_ok(); + cx.config + .expect(["rustup", "toolchain", "install"]) + .await + .is_err() + .with_stderr(snapbox::str![[r#" +info: syncing channel updates for beta-[HOST_TUPLE] +info: latest update on 2015-01-02 for version 1.2.0 (hash-beta-1.2.0) +error: component 'rust-std-[CROSS_ARCH_I]' for target '[HOST_TUPLE]' is unavailable for download for channel 'beta-[HOST_TUPLE]' +... +"#]]); +} + #[tokio::test] async fn pin_dir_override() { let cx = CliTestContext::new(Scenario::SimpleV2).await; From 1f2ee5d1d7cc7e90aa3945d0ce8c30d76a1f80d5 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 24 Nov 2026 10:58:40 +0100 Subject: [PATCH 3/5] refactor(rustup-mode): use imperative loop in `pin_active_toolchain()` --- src/cli/rustup_mode.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 7b142f7d8d..969b47b09c 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -1697,15 +1697,15 @@ fn pin_active_toolchain(qualified: bool, cfg: &Cfg<'_>) -> anyhow::Result None, }; From 8bd4f19f8e7a1bbe4e8077a451b6b2b5b01d6a56 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 24 Nov 2026 11:28:18 +0100 Subject: [PATCH 4/5] fix(rustup-mode): reuse active toolchain's host for `rustup toolchain pin` without overrides --- src/cli/rustup_mode.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 969b47b09c..d148792c6d 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -1695,6 +1695,7 @@ fn pin_active_toolchain(qualified: bool, cfg: &Cfg<'_>) -> anyhow::Result { let tc = ChannelToolchain::new(cfg, desc.clone().complete(&default_host)?)?; + let host = &tc.desc().target; let manifest = tc.get_manifest()?; let mut components = vec![]; @@ -1703,7 +1704,7 @@ fn pin_active_toolchain(qualified: bool, cfg: &Cfg<'_>) -> anyhow::Result Date: Mon, 23 Nov 2026 10:56:00 +0000 Subject: [PATCH 5/5] fix(rustup-mode): backfill non-native `targets` on `rustup toolchain pin` Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- src/cli/rustup_mode.rs | 24 ++++++++++++++++-------- src/config.rs | 2 +- tests/suite/cli_rustup.rs | 14 ++++++++++---- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index d148792c6d..69f76b876c 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -1685,32 +1685,39 @@ async fn toolchain_remove(cfg: &Cfg<'_>, opts: UninstallOpts) -> anyhow::Result< fn pin_active_toolchain(qualified: bool, cfg: &Cfg<'_>) -> anyhow::Result { let default_host = cfg.default_host_tuple()?; - let (mut r#override, backfill_components) = + let (mut r#override, backfill_components_and_targets) = match cfg.find_override_config(cfg.toolchain_override.as_ref())? { Some((o, _)) => (o, None), None => { let default = cfg .get_default_resolvable()? .context("no default toolchain to pin")?; - let components = match &default { + let components_and_targets = match &default { PartialToolchainName::Channel(desc) => { let tc = ChannelToolchain::new(cfg, desc.clone().complete(&default_host)?)?; let host = &tc.desc().target; let manifest = tc.get_manifest()?; - let mut components = vec![]; + let (mut components, mut targets) = (vec![], vec![]); for c in tc.components()? { if !(c.available && c.installed) { continue; } - components.push(manifest.display_name(&c.component, host)); + match c.component.target { + Some(t) if c.component.is_std() && t != *host => { + targets.push(t.to_string()) + } + Some(_) | None => { + components.push(manifest.display_name(&c.component, host)); + } + } } - Some(components) + Some((components, targets)) } PartialToolchainName::Custom(_) => None, }; - (OverrideCfg::from(default), components) + (OverrideCfg::from(default), components_and_targets) } }; if qualified { @@ -1718,8 +1725,9 @@ fn pin_active_toolchain(qualified: bool, cfg: &Cfg<'_>) -> anyhow::Result>, #[serde(skip_serializing_if = "Option::is_none")] - targets: Option>, + pub targets: Option>, #[serde(skip_serializing_if = "Option::is_none")] profile: Option, } diff --git a/tests/suite/cli_rustup.rs b/tests/suite/cli_rustup.rs index fa2f574cce..9acc7cfafa 100644 --- a/tests/suite/cli_rustup.rs +++ b/tests/suite/cli_rustup.rs @@ -5124,6 +5124,7 @@ async fn pin_default() { [toolchain] channel = "beta" components = ["cargo", "rust-docs", "rust-std", "rustc"] +targets = [] "#]], ); @@ -5140,6 +5141,7 @@ components = ["cargo", "rust-docs", "rust-std", "rustc"] [toolchain] channel = "beta-[HOST_TUPLE]" components = ["cargo", "rust-docs", "rust-std", "rustc"] +targets = [] "#]], ); @@ -5178,7 +5180,8 @@ async fn pin_default_with_extra_target() { ... [toolchain] channel = "beta" -components = ["cargo", "rust-docs", "rust-std", "rust-std-[CROSS_ARCH_I]", "rustc"] +components = ["cargo", "rust-docs", "rust-std", "rustc"] +targets = ["[CROSS_ARCH_I]"] "#]], ); @@ -5190,12 +5193,14 @@ components = ["cargo", "rust-docs", "rust-std", "rust-std-[CROSS_ARCH_I]", "rust cx.config .expect(["rustup", "toolchain", "install"]) .await - .is_err() + .is_ok() .with_stderr(snapbox::str![[r#" info: syncing channel updates for beta-[HOST_TUPLE] info: latest update on 2015-01-02 for version 1.2.0 (hash-beta-1.2.0) -error: component 'rust-std-[CROSS_ARCH_I]' for target '[HOST_TUPLE]' is unavailable for download for channel 'beta-[HOST_TUPLE]' -... +info: downloading 5 components +info: the active toolchain `beta-[HOST_TUPLE]` has been installed +info: it's active because: overridden by '[..]/rust-toolchain.toml' + "#]]); } @@ -5454,6 +5459,7 @@ error: found existing override file at 'rust-toolchain.toml', refusing to overwr [toolchain] channel = "stable" components = ["cargo", "rust-docs", "rust-std", "rustc"] +targets = [] "#]], );