Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d29a7cb

Browse files
committedMar 11, 2025
fix(run): Say what the multiple executables are
1 parent b06e29c commit d29a7cb

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed
 

‎src/cargo/ops/cargo_run.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::ffi::OsString;
2+
use std::fmt::Write as _;
23
use std::iter;
34
use std::path::Path;
45

@@ -69,10 +70,20 @@ pub fn run(
6970
names.join(", ")
7071
)
7172
} else {
72-
anyhow::bail!(
73-
"`cargo run` can run at most one executable, but \
73+
let mut message = "`cargo run` can run at most one executable, but \
7474
multiple were specified"
75-
)
75+
.to_owned();
76+
write!(&mut message, "\nhelp: available targets:")?;
77+
for (pkg, bin) in &bins {
78+
write!(
79+
&mut message,
80+
"\n {} `{}` in package `{}`",
81+
bin.kind().description(),
82+
bin.name(),
83+
pkg.name()
84+
)?;
85+
}
86+
anyhow::bail!(message)
7687
}
7788
}
7889

‎tests/testsuite/run.rs

+8
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,11 @@ fn ambiguous_bin_name() {
836836
.with_status(101)
837837
.with_stderr_data(str![[r#"
838838
[ERROR] `cargo run` can run at most one executable, but multiple were specified
839+
[HELP] available targets:
840+
bin `ambiguous` in package `crate1`
841+
bin `ambiguous` in package `crate2`
842+
bin `ambiguous` in package `crate3`
843+
bin `ambiguous` in package `crate4`
839844
840845
"#]])
841846
.run();
@@ -1014,6 +1019,9 @@ fn either_name_or_example() {
10141019
.with_status(101)
10151020
.with_stderr_data(str![[r#"
10161021
[ERROR] `cargo run` can run at most one executable, but multiple were specified
1022+
[HELP] available targets:
1023+
bin `a` in package `foo`
1024+
example `b` in package `foo`
10171025
10181026
"#]])
10191027
.run();

0 commit comments

Comments
 (0)
Failed to load comments.