Skip to content

Commit

Permalink
Auto merge of #9066 - rubenrua:hotfix_sort_bins, r=ehuss
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
bors committed Jan 12, 2021
2 parents 7f41cf6 + eb31d1a commit a73e5b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/cargo/ops/cargo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down
8 changes: 7 additions & 1 deletion tests/testsuite/required_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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();

Expand All @@ -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();
}
Expand Down

0 comments on commit a73e5b7

Please sign in to comment.