Skip to content
Open
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
62 changes: 26 additions & 36 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ async fn target_list(

async fn target_add(
cfg: &Cfg<'_>,
mut targets: Vec<String>,
targets: Vec<String>,
toolchain: Option<PartialToolchainDesc>,
) -> anyhow::Result<ExitCode> {
// XXX: long term move this error to cli ? the normal .into doesn't work
Expand All @@ -1478,44 +1478,33 @@ async fn target_add(
)
.await?;

let components = distributable.components()?;
if targets.contains(&"all".to_string()) {
if targets.len() != 1 {
return Err(anyhow!(
"`rustup target add {}` includes `all`",
targets.join(" ")
));
}
let all = targets.iter().any(|it| it == "all");
if all && targets.len() != 1 {
return Err(anyhow!(
"`rustup target add {}` includes `all`",
targets.join(" ")
));
}

targets.clear();
for component in components {
if component.component.short_name() == "rust-std"
&& component.available
&& !component.installed
{
let target = component
.component
.target
.as_ref()
.expect("rust-std should have a target");
targets.push(target.to_string());
}
}
if all {
distributable
.add_components(distributable.components()?.into_iter().filter_map(|c| {
(c.available && !c.installed && c.component.short_name() == "rust-std")
.then_some(c.component)
}))
.await?;

return Ok(ExitCode::SUCCESS);
}

distributable
.add_components(
targets
.into_iter()
.map(|target| {
Component::new(
"rust-std".to_string(),
Some(TargetTuple::new(target)),
false,
)
})
.collect(),
)
.add_components(targets.into_iter().map(|target| {
Component::new(
"rust-std".to_string(),
Some(TargetTuple::new(target)),
false,
)
}))
.await?;

Ok(ExitCode::SUCCESS)
Expand Down Expand Up @@ -1613,7 +1602,8 @@ async fn component_add(
components
.into_iter()
.map(|component| Component::try_new(&component, &distributable, target.as_ref()))
.collect::<anyhow::Result<_>>()?,
.collect::<anyhow::Result<Vec<_>>>()?
.into_iter(),
)
.await?;

Expand Down
7 changes: 5 additions & 2 deletions src/toolchain/distributable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ impl<'a> DistributableToolchain<'a> {
&self.desc
}

pub(crate) async fn add_components(&self, components: Vec<Component>) -> anyhow::Result<()> {
pub(crate) async fn add_components(
&self,
components: impl Iterator<Item = Component>,
) -> anyhow::Result<()> {
let manifestation = self.get_manifestation()?;
let manifest = self.get_manifest()?;

Expand All @@ -78,7 +81,7 @@ impl<'a> DistributableToolchain<'a> {
.get(&self.desc.target)
.expect("installed manifest should have a known target");

let mut validated_components = Vec::with_capacity(components.len());
let mut validated_components = Vec::with_capacity(components.size_hint().0);

for mut component in components {
if let Some(c) = manifest.rename_component(&component) {
Expand Down