diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 189899561c..4c92cfab6f 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -1340,14 +1340,17 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches) -> Result { if target == default_target { warn!("after removing the default host target, proc-macros and build scripts might no longer build"); } - let has_at_most_one_target = { - let components = distributable.components()?; - // Every component target that is not `None` (wildcard). - let targets = components - .iter() - .filter_map(|c| c.installed.then(|| c.component.target.clone()).flatten()); - targets.unique().at_most_one().is_ok() - }; + // Whether we have at most 1 component target that is not `None` (wildcard). + let has_at_most_one_target = distributable + .components()? + .into_iter() + .filter_map(|c| match (c.installed, c.component.target) { + (true, Some(t)) => Some(t), + _ => None, + }) + .unique() + .at_most_one() + .is_ok(); if has_at_most_one_target { warn!("after removing the last target, no build targets will be available"); } diff --git a/src/lib.rs b/src/lib.rs index af9875c969..b5215ea09f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ pub use crate::errors::*; pub(crate) use crate::notifications::*; pub(crate) use crate::utils::toml_utils; use anyhow::{anyhow, Result}; +use itertools::{chain, Itertools}; #[macro_use] extern crate rs_tracing; @@ -41,23 +42,15 @@ pub static DUP_TOOLS: &[&str] = &["rust-analyzer", "rustfmt", "cargo-fmt"]; // If the given name is one of the tools we proxy. pub fn is_proxyable_tools(tool: &str) -> Result<()> { - if TOOLS - .iter() - .chain(DUP_TOOLS.iter()) - .any(|&name| name == tool) - { + if chain!(TOOLS, DUP_TOOLS).contains(&tool) { Ok(()) } else { - Err(anyhow!(format!( - "unknown proxy name: '{}'; valid proxy names are {}", - tool, - TOOLS - .iter() - .chain(DUP_TOOLS.iter()) + Err(anyhow!( + "unknown proxy name: '{tool}'; valid proxy names are {}", + chain!(TOOLS, DUP_TOOLS) .map(|s| format!("'{s}'")) - .collect::>() - .join(", ") - ))) + .join(", "), + )) } } diff --git a/src/toolchain/distributable.rs b/src/toolchain/distributable.rs index 8bc77901c2..a22b026739 100644 --- a/src/toolchain/distributable.rs +++ b/src/toolchain/distributable.rs @@ -10,7 +10,7 @@ use crate::{ dist::{ config::Config, dist::{Profile, ToolchainDesc}, - manifest::{Component, Manifest}, + manifest::{Component, ComponentStatus, Manifest}, manifestation::{Changes, Manifestation}, prefix::InstallPrefix, }, @@ -115,7 +115,7 @@ impl<'a> DistributableToolchain<'a> { Ok(()) } - pub(crate) fn components(&self) -> anyhow::Result> { + pub(crate) fn components(&self) -> anyhow::Result> { let manifestation = self.get_manifestation()?; let config = manifestation.read_config()?.unwrap_or_default(); let manifest = self.get_manifest()?;