Skip to content

Commit 181de52

Browse files
committed
Auto merge of #5447 - ehuss:ws-error-message, r=alexcrichton
Better error message for `cargo rustc` in a workspace. Fixes #5371
2 parents f2abbe8 + 037a879 commit 181de52

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/cargo/ops/cargo_compile.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,9 @@ impl Packages {
217217
.map(PackageIdSpec::from_package_id)
218218
.filter(|p| opt_out.iter().position(|x| *x == p.name()).is_none())
219219
.collect(),
220-
Packages::Packages(ref packages) if packages.is_empty() => ws.current_opt()
221-
.map(Package::package_id)
222-
.map(PackageIdSpec::from_package_id)
223-
.into_iter()
224-
.collect(),
220+
Packages::Packages(ref packages) if packages.is_empty() => {
221+
vec![PackageIdSpec::from_package_id(ws.current()?.package_id())]
222+
}
225223
Packages::Packages(ref packages) => packages
226224
.iter()
227225
.map(|p| PackageIdSpec::parse(p))

tests/testsuite/workspaces.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fs::{self, File};
33
use std::io::{Read, Write};
44

55
use cargotest::sleep_ms;
6-
use cargotest::support::{execs, git, project};
6+
use cargotest::support::{basic_lib_manifest, execs, git, project};
77
use cargotest::support::registry::Package;
88
use hamcrest::{assert_that, existing_dir, existing_file, is_not};
99

@@ -2338,3 +2338,33 @@ fn relative_rustc() {
23382338
let file = format!("./foo{}", env::consts::EXE_SUFFIX);
23392339
assert_that(p.cargo("build").env("RUSTC", &file), execs().with_status(0));
23402340
}
2341+
2342+
2343+
#[test]
2344+
fn ws_rustc_err() {
2345+
let p = project("ws")
2346+
.file(
2347+
"Cargo.toml",
2348+
r#"
2349+
[workspace]
2350+
members = ["a"]
2351+
"#,
2352+
)
2353+
.file("a/Cargo.toml", &basic_lib_manifest("a"))
2354+
.file("a/src/lib.rs", "")
2355+
.build();
2356+
2357+
assert_that(
2358+
p.cargo("rustc"),
2359+
execs()
2360+
.with_status(101)
2361+
.with_stderr("[ERROR] [..]against an actual package[..]"),
2362+
);
2363+
2364+
assert_that(
2365+
p.cargo("rustdoc"),
2366+
execs()
2367+
.with_status(101)
2368+
.with_stderr("[ERROR] [..]against an actual package[..]"),
2369+
);
2370+
}

0 commit comments

Comments
 (0)