File tree Expand file tree Collapse file tree 2 files changed +30
-12
lines changed
src/cargo/ops/cargo_compile Expand file tree Collapse file tree 2 files changed +30
-12
lines changed Original file line number Diff line number Diff line change @@ -294,26 +294,21 @@ impl<'a> UnitGenerator<'a, '_> {
294294
295295 let unmatched_packages = match self . spec {
296296 Packages :: Default | Packages :: OptOut ( _) | Packages :: All ( _) => {
297- "default-run packages" . to_owned ( )
298- }
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 ! ( "`{}` package" , first)
305- } else {
306- format ! ( "`{}`, ... packages" , first)
307- }
297+ " in default-run packages" . to_owned ( )
308298 }
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" } ;
312307
313308 let mut msg = String :: new ( ) ;
314309 write ! (
315310 msg,
316- "no {target_desc} target {named} `{target_name}` in {unmatched_packages}{suggestion}" ,
311+ "no {target_desc} target {named} `{target_name}`{unmatched_packages}{suggestion}" ,
317312 ) ?;
318313 if !targets_elsewhere. is_empty ( ) {
319314 append_targets_elsewhere ( & mut msg) ?;
Original file line number Diff line number Diff line change @@ -533,6 +533,29 @@ fn fail_with_multiple_packages() {
533533 . run ( ) ;
534534}
535535
536+ #[ cargo_test]
537+ fn fail_with_bad_bin_no_package ( ) {
538+ let p = project ( )
539+ . file (
540+ "src/main.rs" ,
541+ r#"
542+ fn main() { println!("hello a.rs"); }
543+ "# ,
544+ )
545+ . build ( ) ;
546+
547+ p. cargo ( "rustc --bin main" )
548+ . with_status ( 101 )
549+ . with_stderr_data ( str![ [ r#"
550+ [ERROR] no bin target named `main`
551+ [HELP] available bin targets:
552+ foo
553+ ...
554+
555+ "# ] ] )
556+ . run ( ) ;
557+ }
558+
536559#[ cargo_test]
537560fn fail_with_glob ( ) {
538561 let p = project ( )
You can’t perform that action at this time.
0 commit comments