diff --git a/src/cli/common.rs b/src/cli/common.rs index f8f0174990..cc554a38df 100644 --- a/src/cli/common.rs +++ b/src/cli/common.rs @@ -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, + items: impl Iterator, installed_only: bool, quiet: bool, process: &Process, diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index c4397dc20d..7476d32fa9 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -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 } @@ -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, @@ -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, @@ -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,