Skip to content

Custom list tweaks #4351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,12 @@ where
Ok(utils::ExitCode(0))
}

/// Iterates over pairs representing the name of a target or component and a
/// boolean value indicating whether it is installed or not.
/// The boolean value is needed to determine whether to print "(installed)"
/// next to the target/component name."
/// Print a list of items (targets or components) to stdout.
///
/// `items` represents the list of items, with the name and a boolean
/// to represent whether the item is currently installed.
pub(super) fn list_items(
items: impl Iterator<Item = (String, bool)>,
items: impl Iterator<Item = (impl Display, bool)>,
installed_only: bool,
quiet: bool,
process: &Process,
Expand Down
23 changes: 7 additions & 16 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,10 +1177,7 @@ async fn target_list(
common::list_items(
distributable.components()?.into_iter().filter_map(|c| {
if c.component.short_name_in_manifest() == "rust-std" && c.available {
c.component
.target
.as_deref()
.map(|target| (target.to_string(), c.installed))
c.component.target.map(|target| (target, c.installed))
} else {
None
}
Expand All @@ -1192,10 +1189,7 @@ async fn target_list(
} else {
let toolchain = cfg.toolchain_from_partial(toolchain).await?;
common::list_items(
toolchain
.installed_targets()?
.iter()
.map(|s| (s.to_string(), true)),
toolchain.installed_targets()?.iter().map(|s| (s, true)),
installed_only,
quiet,
cfg.process,
Expand Down Expand Up @@ -1297,13 +1291,10 @@ async fn component_list(
// downcasting required because the toolchain files can name any toolchain
if let Ok(distributable) = DistributableToolchain::from_partial(toolchain.clone(), cfg).await {
common::list_items(
distributable.components()?.into_iter().filter_map(|c| {
if c.available {
Some((c.name, c.installed))
} else {
None
}
}),
distributable
.components()?
.into_iter()
.filter_map(|c| c.available.then_some((c.name, c.installed))),
installed_only,
quiet,
cfg.process,
Expand All @@ -1314,7 +1305,7 @@ async fn component_list(
toolchain
.installed_components()?
.iter()
.map(|s| (s.name().to_string(), true)),
.map(|s| (s.name(), true)),
installed_only,
quiet,
cfg.process,
Expand Down