@@ -475,6 +475,16 @@ fn format(opt: Opt) -> Result<i32> {
475
475
return format_string ( buf, opt) ;
476
476
}
477
477
478
+ if let Some ( file) = opt. files . iter ( ) . find ( |f| !f. exists ( ) ) {
479
+ return Err ( format_err ! (
480
+ "Error: file `{}` does not exist" ,
481
+ file. display( )
482
+ ) ) ;
483
+ }
484
+ if let Some ( dir) = opt. files . iter ( ) . find ( |f| f. is_dir ( ) ) {
485
+ return Err ( format_err ! ( "Error: `{}` is a directory" , dir. display( ) ) ) ;
486
+ }
487
+
478
488
let ( config, config_path) = load_config ( None , Some ( & opt) ) ?;
479
489
480
490
if config. verbose ( ) == Verbosity :: Verbose {
@@ -489,30 +499,22 @@ fn format(opt: Opt) -> Result<i32> {
489
499
for pair in FileConfigPairIter :: new ( & opt, config_path. is_some ( ) ) {
490
500
let file = pair. file ;
491
501
492
- if !file. exists ( ) {
493
- eprintln ! ( "Error: file `{}` does not exist" , file. display( ) ) ;
494
- session. add_operational_error ( ) ;
495
- } else if file. is_dir ( ) {
496
- eprintln ! ( "Error: `{}` is a directory" , file. display( ) ) ;
497
- session. add_operational_error ( ) ;
498
- } else {
499
- if let FileConfig :: Local ( local_config, config_path) = pair. config {
500
- if let Some ( path) = config_path {
501
- if local_config. verbose ( ) == Verbosity :: Verbose {
502
- println ! (
503
- "Using rustfmt config file {} for {}" ,
504
- path. display( ) ,
505
- file. display( )
506
- ) ;
507
- }
502
+ if let FileConfig :: Local ( local_config, config_path) = pair. config {
503
+ if let Some ( path) = config_path {
504
+ if local_config. verbose ( ) == Verbosity :: Verbose {
505
+ println ! (
506
+ "Using rustfmt config file {} for {}" ,
507
+ path. display( ) ,
508
+ file. display( )
509
+ ) ;
508
510
}
509
-
510
- session. override_config ( local_config, |sess| {
511
- format_and_emit_report ( sess, Input :: File ( file. to_path_buf ( ) ) )
512
- } ) ;
513
- } else {
514
- format_and_emit_report ( & mut session, Input :: File ( file. to_path_buf ( ) ) ) ;
515
511
}
512
+
513
+ session. override_config ( local_config, |sess| {
514
+ format_and_emit_report ( sess, Input :: File ( file. to_path_buf ( ) ) )
515
+ } ) ;
516
+ } else {
517
+ format_and_emit_report ( & mut session, Input :: File ( file. to_path_buf ( ) ) ) ;
516
518
}
517
519
}
518
520
0 commit comments