Skip to content

Commit f83e11a

Browse files
committed
fix(rustc): Don't panic on unknown bins
This takes the most surgical, direct route to addressing the problem. Alternatively, we could look into why `cargo rustc` and `cargo check` are different. Fixes #15493
1 parent 981ea84 commit f83e11a

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/cargo/ops/cargo_compile/unit_generator.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,11 @@ impl<'a> UnitGenerator<'a, '_> {
296296
Packages::Default | Packages::OptOut(_) | Packages::All(_) => {
297297
" in default-run packages".to_owned()
298298
}
299-
Packages::Packages(packages) => {
300-
let first = packages
301-
.first()
302-
.expect("The number of packages must be at least 1");
303-
if packages.len() == 1 {
304-
format!(" in `{}` package", first)
305-
} else {
306-
format!(" in `{}`, ... packages", first)
307-
}
308-
}
299+
Packages::Packages(packages) => match packages.len() {
300+
0 => String::new(),
301+
1 => format!(" in `{}` package", packages[0]),
302+
_ => format!(" in `{}`, ... packages", packages[0]),
303+
},
309304
};
310305

311306
let named = if is_glob { "matches pattern" } else { "named" };

tests/testsuite/rustc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,9 @@ fn fail_with_bad_bin_no_package() {
547547
p.cargo("rustc --bin main")
548548
.with_status(101)
549549
.with_stderr_data(str![[r#"
550-
551-
thread 'main' panicked [..]:
552-
The number of packages must be at least 1
550+
[ERROR] no bin target named `main`
551+
[HELP] available bin targets:
552+
foo
553553
...
554554
555555
"#]])

0 commit comments

Comments
 (0)