Better error message for `cargo rustc` in a workspace.
authorEric Huss <eric@huss.org>
Tue, 1 May 2018 03:39:07 +0000 (20:39 -0700)
committerEric Huss <eric@huss.org>
Tue, 1 May 2018 03:39:07 +0000 (20:39 -0700)
Fixes #5371

src/cargo/ops/cargo_compile.rs
tests/testsuite/workspaces.rs

index 624659784717d8bb92c535a8953926489e80b26a..cbf03a71b1cda09c230c32e00c781a0562e12913 100644 (file)
@@ -217,11 +217,9 @@ impl Packages {
                 .map(PackageIdSpec::from_package_id)
                 .filter(|p| opt_out.iter().position(|x| *x == p.name()).is_none())
                 .collect(),
-            Packages::Packages(ref packages) if packages.is_empty() => ws.current_opt()
-                .map(Package::package_id)
-                .map(PackageIdSpec::from_package_id)
-                .into_iter()
-                .collect(),
+            Packages::Packages(ref packages) if packages.is_empty() => {
+                vec![PackageIdSpec::from_package_id(ws.current()?.package_id())]
+            }
             Packages::Packages(ref packages) => packages
                 .iter()
                 .map(|p| PackageIdSpec::parse(p))
index 191c518f3f2750473d9cb806306b9694b3db88f1..d496005783d30c772383a2e93a3588f49c4255aa 100644 (file)
@@ -3,7 +3,7 @@ use std::fs::{self, File};
 use std::io::{Read, Write};
 
 use cargotest::sleep_ms;
-use cargotest::support::{execs, git, project};
+use cargotest::support::{basic_lib_manifest, execs, git, project};
 use cargotest::support::registry::Package;
 use hamcrest::{assert_that, existing_dir, existing_file, is_not};
 
@@ -2338,3 +2338,33 @@ fn relative_rustc() {
     let file = format!("./foo{}", env::consts::EXE_SUFFIX);
     assert_that(p.cargo("build").env("RUSTC", &file), execs().with_status(0));
 }
+
+
+#[test]
+fn ws_rustc_err() {
+    let p = project("ws")
+        .file(
+            "Cargo.toml",
+            r#"
+            [workspace]
+            members = ["a"]
+        "#,
+        )
+        .file("a/Cargo.toml", &basic_lib_manifest("a"))
+        .file("a/src/lib.rs", "")
+        .build();
+
+    assert_that(
+        p.cargo("rustc"),
+        execs()
+            .with_status(101)
+            .with_stderr("[ERROR] [..]against an actual package[..]"),
+    );
+
+    assert_that(
+        p.cargo("rustdoc"),
+        execs()
+            .with_status(101)
+            .with_stderr("[ERROR] [..]against an actual package[..]"),
+    );
+}