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, '_> {
294
294
295
295
let unmatched_packages = match self . spec {
296
296
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 ( )
308
298
}
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
+ } ,
309
304
} ;
310
305
311
306
let named = if is_glob { "matches pattern" } else { "named" } ;
312
307
313
308
let mut msg = String :: new ( ) ;
314
309
write ! (
315
310
msg,
316
- "no {target_desc} target {named} `{target_name}` in {unmatched_packages}{suggestion}" ,
311
+ "no {target_desc} target {named} `{target_name}`{unmatched_packages}{suggestion}" ,
317
312
) ?;
318
313
if !targets_elsewhere. is_empty ( ) {
319
314
append_targets_elsewhere ( & mut msg) ?;
Original file line number Diff line number Diff line change @@ -533,6 +533,29 @@ fn fail_with_multiple_packages() {
533
533
. run ( ) ;
534
534
}
535
535
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
+
536
559
#[ cargo_test]
537
560
fn fail_with_glob ( ) {
538
561
let p = project ( )
You can’t perform that action at this time.
0 commit comments