@@ -11,6 +11,8 @@ use std::io::{self, stdout, Read, Write};
1111use  std:: path:: { Path ,  PathBuf } ; 
1212use  std:: str:: FromStr ; 
1313
14+ use  ansi_term:: Colour :: Red ; 
15+ 
1416use  getopts:: { Matches ,  Options } ; 
1517
1618use  crate :: rustfmt:: { 
@@ -73,6 +75,14 @@ pub enum OperationError {
7375    /// An io error during reading or writing. 
7476     #[ fail( display = "io error: {}" ,  _0) ]  
7577    IoError ( IoError ) , 
78+     /// Attempt to use --check with stdin, which isn't currently 
79+      /// supported. 
80+      #[ fail( display = "The `--check` option is not supported with standard input." ) ]  
81+     CheckWithStdin , 
82+     /// Attempt to use --emit=json with stdin, which isn't currently 
83+      /// supported. 
84+      #[ fail( display = "Using `--emit` other than stdout is not supported with standard input." ) ]  
85+     EmitWithStdin , 
7686} 
7787
7888impl  From < IoError >  for  OperationError  { 
@@ -242,6 +252,14 @@ fn format_string(input: String, options: GetOptsOptions) -> Result<i32, FailureE
242252    // try to read config from local directory 
243253    let  ( mut  config,  _)  = load_config ( Some ( Path :: new ( "." ) ) ,  Some ( options. clone ( ) ) ) ?; 
244254
255+     if  options. check  { 
256+         return  Err ( OperationError :: CheckWithStdin . into ( ) ) ; 
257+     } 
258+     if  let  Some ( emit_mode)  = options. emit_mode  { 
259+         if  emit_mode != EmitMode :: Stdout  { 
260+             return  Err ( OperationError :: EmitWithStdin . into ( ) ) ; 
261+         } 
262+     } 
245263    // emit mode is always Stdout for Stdin. 
246264    config. set ( ) . emit_mode ( EmitMode :: Stdout ) ; 
247265    config. set ( ) . verbose ( Verbosity :: Quiet ) ; 
@@ -486,7 +504,7 @@ struct GetOptsOptions {
486504    verbose :  bool , 
487505    config_path :  Option < PathBuf > , 
488506    inline_config :  HashMap < String ,  String > , 
489-     emit_mode :  EmitMode , 
507+     emit_mode :  Option < EmitMode > , 
490508    backup :  bool , 
491509    check :  bool , 
492510    edition :  Option < Edition > , 
@@ -497,6 +515,12 @@ struct GetOptsOptions {
497515    print_misformatted_file_names :  bool , 
498516} 
499517
518+ fn  deprecate_skip_children ( )  { 
519+     let  msg = "Option --skip-children is deprecated since it is now the default to not format \  
520+                 submodules of given files (#3587)"; 
521+     eprintln ! ( "{}: {}" ,  Red . bold( ) . paint( "Deprecation" ) ,  msg) ; 
522+ } 
523+ 
500524impl  GetOptsOptions  { 
501525    pub  fn  from_matches ( matches :  & Matches )  -> Result < GetOptsOptions ,  FailureError >  { 
502526        let  mut  options = GetOptsOptions :: default ( ) ; 
@@ -513,6 +537,7 @@ impl GetOptsOptions {
513537
514538            if  options. unstable_features  { 
515539                if  matches. opt_present ( "skip-children" )  { 
540+                     deprecate_skip_children ( ) ; 
516541                    options. skip_children  = Some ( true ) ; 
517542                } 
518543                if  matches. opt_present ( "error-on-unformatted" )  { 
@@ -524,6 +549,7 @@ impl GetOptsOptions {
524549            }  else  { 
525550                let  mut  unstable_options = vec ! [ ] ; 
526551                if  matches. opt_present ( "skip-children" )  { 
552+                     deprecate_skip_children ( ) ; 
527553                    unstable_options. push ( "`--skip-children`" ) ; 
528554                } 
529555                if  matches. opt_present ( "error-on-unformatted" )  { 
@@ -574,7 +600,7 @@ impl GetOptsOptions {
574600                return  Err ( format_err ! ( "Invalid to use `--emit` and `--check`" ) ) ; 
575601            } 
576602
577-             options. emit_mode  = emit_mode_from_emit_str ( emit_str) ?; 
603+             options. emit_mode  = Some ( emit_mode_from_emit_str ( emit_str) ?) ; 
578604        } 
579605
580606        if  let  Some ( ref  edition_str)  = matches. opt_str ( "edition" )  { 
@@ -590,11 +616,13 @@ impl GetOptsOptions {
590616        } 
591617
592618        if  !rust_nightly { 
593-             if  !STABLE_EMIT_MODES . contains ( & options. emit_mode )  { 
594-                 return  Err ( format_err ! ( 
595-                     "Invalid value for `--emit` - using an unstable \  
596-                       value without `--unstable-features`", 
597-                 ) ) ; 
619+             if  let  Some ( ref  emit_mode)  = options. emit_mode  { 
620+                 if  !STABLE_EMIT_MODES . contains ( emit_mode)  { 
621+                     return  Err ( format_err ! ( 
622+                         "Invalid value for `--emit` - using an unstable \  
623+                           value without `--unstable-features`", 
624+                     ) ) ; 
625+                 } 
598626            } 
599627        } 
600628
@@ -643,8 +671,8 @@ impl CliOptions for GetOptsOptions {
643671        } 
644672        if  self . check  { 
645673            config. set ( ) . emit_mode ( EmitMode :: Diff ) ; 
646-         }  else  { 
647-             config. set ( ) . emit_mode ( self . emit_mode ) ; 
674+         }  else  if   let   Some ( emit_mode )  =  self . emit_mode   { 
675+             config. set ( ) . emit_mode ( emit_mode) ; 
648676        } 
649677        if  self . backup  { 
650678            config. set ( ) . make_backup ( true ) ; 
0 commit comments