Skip to content

Commit 525323f

Browse files
committed
Auto merge of #4494 - RalfJung:virtual, r=matklad
cargo_compile: iterate packages once, not three times I forgot to push this into <#4492> r? @matklad
2 parents 4864b5c + f490f16 commit 525323f

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

src/cargo/ops/cargo_compile.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,17 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
231231
&specs)?;
232232
let (packages, resolve_with_overrides) = resolve;
233233

234-
let mut pkgids = Vec::new();
235-
if specs.len() > 0 {
236-
for p in specs.iter() {
237-
pkgids.push(p.query(resolve_with_overrides.iter())?);
238-
}
239-
} else {
234+
if specs.is_empty() {
240235
return Err(format!("manifest path `{}` contains no package: The manifest is virtual, \
241236
and the workspace has no members.", ws.current_manifest().display()).into());
242237
};
243238

244-
let to_builds = pkgids.iter().map(|id| {
245-
packages.get(id)
246-
}).collect::<CargoResult<Vec<_>>>()?;
247-
for p in to_builds.iter() {
239+
let to_builds = specs.iter().map(|p| {
240+
let pkgid = p.query(resolve_with_overrides.iter())?;
241+
let p = packages.get(pkgid)?;
248242
p.manifest().print_teapot(ws.config());
249-
}
243+
Ok(p)
244+
}).collect::<CargoResult<Vec<_>>>()?;
250245

251246
let mut general_targets = Vec::new();
252247
let mut package_targets = Vec::new();

src/cargo/ops/cargo_doc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
2222
&specs)?;
2323
let (packages, resolve_with_overrides) = resolve;
2424

25-
let mut pkgs = Vec::new();
26-
if specs.len() > 0 {
27-
for p in specs.iter() {
28-
pkgs.push(packages.get(p.query(resolve_with_overrides.iter())?)?);
29-
}
30-
} else {
25+
if specs.is_empty() {
3126
return Err(format!("manifest path `{}` contains no package: The manifest is virtual, \
3227
and the workspace has no members.", ws.current_manifest().display()).into());
3328
};
3429

30+
let pkgs = specs.iter().map(|p| {
31+
let pkgid = p.query(resolve_with_overrides.iter())?;
32+
packages.get(pkgid)
33+
}).collect::<CargoResult<Vec<_>>>()?;
34+
3535
let mut lib_names = HashSet::new();
3636
let mut bin_names = HashSet::new();
3737
for package in &pkgs {

0 commit comments

Comments
 (0)