From: Kornel Date: Sat, 28 Oct 2017 22:03:15 +0000 (+0100) Subject: List available binary names X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~5^2~5^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c22f3f5287384c7e4a2d45eb8de2cbfda23cb68e;p=cargo.git List available binary names --- diff --git a/src/cargo/ops/cargo_run.rs b/src/cargo/ops/cargo_run.rs index 3a4e7f6f2..636a62646 100644 --- a/src/cargo/ops/cargo_run.rs +++ b/src/cargo/ops/cargo_run.rs @@ -25,25 +25,28 @@ pub fn run(ws: &Workspace, } }; - let mut bins = pkg.manifest().targets().iter().filter(|a| { + let bins: Vec<_> = pkg.manifest().targets().iter().filter(|a| { !a.is_lib() && !a.is_custom_build() && if !options.filter.is_specific() { a.is_bin() } else { options.filter.matches(a) } - }); - if bins.next().is_none() { + }) + .map(|bin| bin.name()) + .collect(); + + if bins.len() == 0 { if !options.filter.is_specific() { bail!("a bin target must be available for `cargo run`") } else { // this will be verified in cargo_compile } } - if bins.next().is_some() { + if bins.len() > 1 { if !options.filter.is_specific() { bail!("`cargo run` requires that a project only have one \ executable; use the `--bin` option to specify which one \ - to run") + to run ({})", bins.join(", ")) } else { bail!("`cargo run` can run at most one executable, but \ multiple were specified") diff --git a/tests/required-features.rs b/tests/required-features.rs index 0f71d6d93..cdcc8d494 100644 --- a/tests/required-features.rs +++ b/tests/required-features.rs @@ -996,5 +996,5 @@ fn run_default_multiple_required_features() { assert_that(p.cargo("run"), execs().with_status(101).with_stderr("\ error: `cargo run` requires that a project only have one executable; \ -use the `--bin` option to specify which one to run")); +use the `--bin` option to specify which one to run (foo1, foo2)")); } diff --git a/tests/run.rs b/tests/run.rs index 449c91caf..66e5350e4 100644 --- a/tests/run.rs +++ b/tests/run.rs @@ -256,7 +256,7 @@ fn too_many_bins() { execs().with_status(101) .with_stderr("[ERROR] `cargo run` requires that a project only \ have one executable; use the `--bin` option \ - to specify which one to run\n")); + to specify which one to run ([..])\n")); } #[test] @@ -278,7 +278,7 @@ fn too_many_bins_implicit() { execs().with_status(101) .with_stderr("[ERROR] `cargo run` requires that a project only \ have one executable; use the `--bin` option \ - to specify which one to run\n")); + to specify which one to run ([..])\n")); } #[test]