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
This commit is contained in:
Ed Page 2025-05-06 11:13:30 -05:00
parent 981ea84bdc
commit f83e11acfe
2 changed files with 8 additions and 13 deletions

View File

@ -296,16 +296,11 @@ impl<'a> UnitGenerator<'a, '_> {
Packages::Default | Packages::OptOut(_) | Packages::All(_) => {
" in default-run packages".to_owned()
}
Packages::Packages(packages) => {
let first = packages
.first()
.expect("The number of packages must be at least 1");
if packages.len() == 1 {
format!(" in `{}` package", first)
} else {
format!(" in `{}`, ... packages", first)
}
}
Packages::Packages(packages) => match packages.len() {
0 => String::new(),
1 => format!(" in `{}` package", packages[0]),
_ => format!(" in `{}`, ... packages", packages[0]),
},
};
let named = if is_glob { "matches pattern" } else { "named" };

View File

@ -547,9 +547,9 @@ fn fail_with_bad_bin_no_package() {
p.cargo("rustc --bin main")
.with_status(101)
.with_stderr_data(str![[r#"
thread 'main' panicked [..]:
The number of packages must be at least 1
[ERROR] no bin target named `main`
[HELP] available bin targets:
foo
...
"#]])