@@ -5,7 +5,7 @@ extern crate lazy_static;
55use std:: collections:: HashMap ;
66use std:: env;
77use std:: fmt;
8- use std:: io:: { self , stdout, Error as IoError , Read , Write , stdin } ;
8+ use std:: io:: { self , stdin , stdout, Error as IoError , Read , Write } ;
99use std:: path:: { Path , PathBuf } ;
1010use std:: str:: FromStr ;
1111
@@ -41,7 +41,7 @@ fn main() {
4141
4242/// Format Rust code
4343#[ derive( Debug , StructOpt , Clone ) ]
44- #[ structopt( name = "rustfmt" , version = include_str!( concat!( env!( "OUT_DIR" ) , "/version-info.txt" ) ) ) ]
44+ #[ structopt( name = "rustfmt" , version = include_str!( concat!( env!( "OUT_DIR" ) , "/version-info.txt" ) ) ) ]
4545struct Opt {
4646 /// Run in 'check' mode.
4747 ///
@@ -50,8 +50,8 @@ struct Opt {
5050 #[ structopt( short, long) ]
5151 check : bool ,
5252 /// Specify the format of rustfmt's output.
53- #[ cfg_attr( nightly, structopt( long, name= "files|stdout|checkstyle|json" ) ) ]
54- #[ cfg_attr( not( nightly) , structopt( long, name= "files|stdout" ) ) ]
53+ #[ cfg_attr( nightly, structopt( long, name = "files|stdout|checkstyle|json" ) ) ]
54+ #[ cfg_attr( not( nightly) , structopt( long, name = "files|stdout" ) ) ]
5555 emit : Option < Emit > ,
5656 /// A path to the configuration file.
5757 #[ structopt( long = "config-path" , parse( from_os_str) ) ]
@@ -92,7 +92,6 @@ struct Opt {
9292 verbose : bool ,
9393
9494 // Nightly-only options.
95-
9695 /// Limit formatting to specified ranges.
9796 ///
9897 /// If you want to restrict reformatting to specific sets of lines, you can
@@ -124,7 +123,6 @@ struct Opt {
124123 error_on_unformatted : bool ,
125124
126125 // Positional arguments.
127-
128126 #[ structopt( parse( from_os_str) ) ]
129127 files : Vec < PathBuf > ,
130128}
@@ -148,22 +146,23 @@ impl FromStr for InlineConfig {
148146
149147 s. split ( ',' )
150148 . map (
151- |key_val| match key_val. char_indices ( ) . find ( |( _, ch) | * ch == '=' ) {
152- Some ( ( middle, _) ) => {
153- let ( key, val) = ( & key_val[ ..middle] , & key_val[ middle + 1 ..] ) ;
154- if !Config :: is_valid_key_val ( key, val) {
155- Err ( format_err ! ( "invalid key=val pair: `{}`" , key_val) )
156- } else {
157- Ok ( ( key. to_string ( ) , val. to_string ( ) ) )
149+ |key_val| match key_val. char_indices ( ) . find ( |( _, ch) | * ch == '=' ) {
150+ Some ( ( middle, _) ) => {
151+ let ( key, val) = ( & key_val[ ..middle] , & key_val[ middle + 1 ..] ) ;
152+ if !Config :: is_valid_key_val ( key, val) {
153+ Err ( format_err ! ( "invalid key=val pair: `{}`" , key_val) )
154+ } else {
155+ Ok ( ( key. to_string ( ) , val. to_string ( ) ) )
156+ }
158157 }
159- }
160158
161- None => Err ( format_err ! (
159+ None => Err ( format_err ! (
162160 "--config expects comma-separated list of key=val pairs, found `{}`" ,
163161 key_val
164162 ) ) ,
165- } ,
166- ) . collect :: < Result < HashMap < _ , _ > , _ > > ( )
163+ } ,
164+ )
165+ . collect :: < Result < HashMap < _ , _ > , _ > > ( )
167166 . map ( |map| InlineConfig ( map, false ) )
168167 }
169168}
@@ -183,7 +182,10 @@ impl FromStr for PrintConfig {
183182 "default" => Ok ( PrintConfig :: Default ) ,
184183 "minimal" => Ok ( PrintConfig :: Minimal ) ,
185184 "current" => Ok ( PrintConfig :: Current ) ,
186- _ => Err ( format ! ( "expected one of [current,default,minimal], found `{}`" , s) ) ,
185+ _ => Err ( format ! (
186+ "expected one of [current,default,minimal], found `{}`" ,
187+ s
188+ ) ) ,
187189 }
188190 }
189191}
@@ -280,7 +282,6 @@ impl Opt {
280282 }
281283}
282284
283-
284285/// Rustfmt operations errors.
285286#[ derive( Error , Debug ) ]
286287pub enum OperationError {
@@ -347,7 +348,9 @@ impl CliOptions for Opt {
347348fn execute ( mut opt : Opt ) -> Result < i32 > {
348349 opt. verify ( ) ?;
349350
350- if opt. inline_config . as_ref ( ) . map_or ( false , |inline_configs| inline_configs. iter ( ) . any ( InlineConfig :: is_help) ) {
351+ if opt. inline_config . as_ref ( ) . map_or ( false , |inline_configs| {
352+ inline_configs. iter ( ) . any ( InlineConfig :: is_help)
353+ } ) {
351354 Config :: print_docs ( & mut stdout ( ) , cfg ! ( nightly) ) ;
352355 return Ok ( 0 ) ;
353356 }
@@ -369,10 +372,12 @@ fn print_default_config() -> Result<i32> {
369372}
370373
371374fn print_config ( opt : & Opt , print_config : PrintConfig ) -> Result < i32 > {
372- let ( config, config_path) =
373- load_config ( env:: current_dir ( ) . ok ( ) . as_ref ( ) . map ( PathBuf :: as_path) , Some ( opt) ) ?;
374- let actual_config = FileConfigPairIter :: new ( & opt, config_path. is_some ( ) )
375- . find_map ( |pair| match pair. config {
375+ let ( config, config_path) = load_config (
376+ env:: current_dir ( ) . ok ( ) . as_ref ( ) . map ( PathBuf :: as_path) ,
377+ Some ( opt) ,
378+ ) ?;
379+ let actual_config =
380+ FileConfigPairIter :: new ( & opt, config_path. is_some ( ) ) . find_map ( |pair| match pair. config {
376381 FileConfig :: Local ( config, Some ( _) ) => Some ( config) ,
377382 _ => None ,
378383 } ) ;
@@ -436,8 +441,7 @@ struct FileConfigPairIter<'a> {
436441 opt : & ' a Opt ,
437442}
438443
439- impl < ' a > FileConfigPairIter < ' a >
440- {
444+ impl < ' a > FileConfigPairIter < ' a > {
441445 fn new ( opt : & ' a Opt , has_config_from_commandline : bool ) -> Self {
442446 FileConfigPairIter {
443447 has_config_from_commandline,
@@ -447,8 +451,7 @@ impl<'a> FileConfigPairIter<'a>
447451 }
448452}
449453
450- impl < ' a > Iterator for FileConfigPairIter < ' a >
451- {
454+ impl < ' a > Iterator for FileConfigPairIter < ' a > {
452455 type Item = FileConfigPair < ' a > ;
453456
454457 fn next ( & mut self ) -> Option < Self :: Item > {
@@ -461,13 +464,11 @@ impl<'a> Iterator for FileConfigPairIter<'a>
461464 FileConfig :: Local ( local_config, config_path)
462465 } ;
463466
464- Some ( FileConfigPair { file, config} )
467+ Some ( FileConfigPair { file, config } )
465468 }
466469}
467470
468- fn format (
469- opt : Opt ,
470- ) -> Result < i32 > {
471+ fn format ( opt : Opt ) -> Result < i32 > {
471472 if opt. files . is_empty ( ) {
472473 let mut buf = String :: new ( ) ;
473474 stdin ( ) . read_to_string ( & mut buf) ?;
0 commit comments