diff --git a/src/cargo/ops/cargo_compile/unit_generator.rs b/src/cargo/ops/cargo_compile/unit_generator.rs index c11406bc4..3c984f476 100644 --- a/src/cargo/ops/cargo_compile/unit_generator.rs +++ b/src/cargo/ops/cargo_compile/unit_generator.rs @@ -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" }; diff --git a/tests/testsuite/rustc.rs b/tests/testsuite/rustc.rs index 8c17fd2bc..da32f20ac 100644 --- a/tests/testsuite/rustc.rs +++ b/tests/testsuite/rustc.rs @@ -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 ... "#]])