From 14979f66ee0ef4eb7058161a4f8fdb243c5a9723 Mon Sep 17 00:00:00 2001 From: rubenrua Date: Tue, 12 Jan 2021 08:46:25 +0100 Subject: [PATCH 1/2] Sort available binaries when multiple From: ``` error: `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key. available binaries: basic-tutorial-13, basic-tutorial-6, basic-tutorial-1, basic-tutorial-4, basic-tutorial-9, basic-tutorial-2, basic-tutorial-3, basic-tutorial-5, basic-tutorial-12, playback-tutorial-4, basic-tutorial-8, basic-tutorial-7 ``` To: ``` error: `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key. available binaries: basic-tutorial-1, basic-tutorial-12, basic-tutorial-13, basic-tutorial-2, basic-tutorial-3, basic-tutorial-4, basic-tutorial-5, basic-tutorial-6, basic-tutorial-7, basic-tutorial-8, basic-tutorial-9, playback-tutorial-4 ``` --- src/cargo/ops/cargo_run.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_run.rs b/src/cargo/ops/cargo_run.rs index d95b0185176..6e8712ff09e 100644 --- a/src/cargo/ops/cargo_run.rs +++ b/src/cargo/ops/cargo_run.rs @@ -55,10 +55,11 @@ pub fn run( if bins.len() > 1 { if !options.filter.is_specific() { - let names: Vec<&str> = bins + let mut names: Vec<&str> = bins .into_iter() .map(|(_pkg, target)| target.name()) .collect(); + names.sort(); anyhow::bail!( "`cargo run` could not determine which binary to run. \ Use the `--bin` option to specify a binary, \ From eb31d1ae9beefdb86659872ca0c1b36379950e5e Mon Sep 17 00:00:00 2001 From: rubenrua Date: Tue, 12 Jan 2021 23:10:51 +0100 Subject: [PATCH 2/2] Test for sort available binaries when multiple --- tests/testsuite/required_features.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/required_features.rs b/tests/testsuite/required_features.rs index eabc9aaf289..55f650d4b3d 100644 --- a/tests/testsuite/required_features.rs +++ b/tests/testsuite/required_features.rs @@ -1169,6 +1169,11 @@ fn run_default_multiple_required_features() { path = "src/foo1.rs" required-features = ["a"] + [[bin]] + name = "foo3" + path = "src/foo3.rs" + required-features = ["b"] + [[bin]] name = "foo2" path = "src/foo2.rs" @@ -1177,6 +1182,7 @@ fn run_default_multiple_required_features() { ) .file("src/lib.rs", "") .file("src/foo1.rs", "extern crate foo; fn main() {}") + .file("src/foo3.rs", "extern crate foo; fn main() {}") .file("src/foo2.rs", "extern crate foo; fn main() {}") .build(); @@ -1185,7 +1191,7 @@ fn run_default_multiple_required_features() { .with_stderr( "\ error: `cargo run` could not determine which binary to run[..] -available binaries: foo1, foo2", +available binaries: foo1, foo2, foo3", ) .run(); }