@@ -5,7 +5,7 @@ extern crate lazy_static;
5
5
use std:: collections:: HashMap ;
6
6
use std:: env;
7
7
use 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 } ;
9
9
use std:: path:: { Path , PathBuf } ;
10
10
use std:: str:: FromStr ;
11
11
@@ -41,7 +41,7 @@ fn main() {
41
41
42
42
/// Format Rust code
43
43
#[ 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" ) ) ) ]
45
45
struct Opt {
46
46
/// Run in 'check' mode.
47
47
///
@@ -50,8 +50,8 @@ struct Opt {
50
50
#[ structopt( short, long) ]
51
51
check : bool ,
52
52
/// 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" ) ) ]
55
55
emit : Option < Emit > ,
56
56
/// A path to the configuration file.
57
57
#[ structopt( long = "config-path" , parse( from_os_str) ) ]
@@ -92,7 +92,6 @@ struct Opt {
92
92
verbose : bool ,
93
93
94
94
// Nightly-only options.
95
-
96
95
/// Limit formatting to specified ranges.
97
96
///
98
97
/// If you want to restrict reformatting to specific sets of lines, you can
@@ -124,7 +123,6 @@ struct Opt {
124
123
error_on_unformatted : bool ,
125
124
126
125
// Positional arguments.
127
-
128
126
#[ structopt( parse( from_os_str) ) ]
129
127
files : Vec < PathBuf > ,
130
128
}
@@ -148,22 +146,23 @@ impl FromStr for InlineConfig {
148
146
149
147
s. split ( ',' )
150
148
. 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
+ }
158
157
}
159
- }
160
158
161
- None => Err ( format_err ! (
159
+ None => Err ( format_err ! (
162
160
"--config expects comma-separated list of key=val pairs, found `{}`" ,
163
161
key_val
164
162
) ) ,
165
- } ,
166
- ) . collect :: < Result < HashMap < _ , _ > , _ > > ( )
163
+ } ,
164
+ )
165
+ . collect :: < Result < HashMap < _ , _ > , _ > > ( )
167
166
. map ( |map| InlineConfig ( map, false ) )
168
167
}
169
168
}
@@ -183,7 +182,10 @@ impl FromStr for PrintConfig {
183
182
"default" => Ok ( PrintConfig :: Default ) ,
184
183
"minimal" => Ok ( PrintConfig :: Minimal ) ,
185
184
"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
+ ) ) ,
187
189
}
188
190
}
189
191
}
@@ -280,7 +282,6 @@ impl Opt {
280
282
}
281
283
}
282
284
283
-
284
285
/// Rustfmt operations errors.
285
286
#[ derive( Error , Debug ) ]
286
287
pub enum OperationError {
@@ -347,7 +348,9 @@ impl CliOptions for Opt {
347
348
fn execute ( mut opt : Opt ) -> Result < i32 > {
348
349
opt. verify ( ) ?;
349
350
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
+ } ) {
351
354
Config :: print_docs ( & mut stdout ( ) , cfg ! ( nightly) ) ;
352
355
return Ok ( 0 ) ;
353
356
}
@@ -369,10 +372,12 @@ fn print_default_config() -> Result<i32> {
369
372
}
370
373
371
374
fn 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 {
376
381
FileConfig :: Local ( config, Some ( _) ) => Some ( config) ,
377
382
_ => None ,
378
383
} ) ;
@@ -436,8 +441,7 @@ struct FileConfigPairIter<'a> {
436
441
opt : & ' a Opt ,
437
442
}
438
443
439
- impl < ' a > FileConfigPairIter < ' a >
440
- {
444
+ impl < ' a > FileConfigPairIter < ' a > {
441
445
fn new ( opt : & ' a Opt , has_config_from_commandline : bool ) -> Self {
442
446
FileConfigPairIter {
443
447
has_config_from_commandline,
@@ -447,8 +451,7 @@ impl<'a> FileConfigPairIter<'a>
447
451
}
448
452
}
449
453
450
- impl < ' a > Iterator for FileConfigPairIter < ' a >
451
- {
454
+ impl < ' a > Iterator for FileConfigPairIter < ' a > {
452
455
type Item = FileConfigPair < ' a > ;
453
456
454
457
fn next ( & mut self ) -> Option < Self :: Item > {
@@ -461,13 +464,11 @@ impl<'a> Iterator for FileConfigPairIter<'a>
461
464
FileConfig :: Local ( local_config, config_path)
462
465
} ;
463
466
464
- Some ( FileConfigPair { file, config} )
467
+ Some ( FileConfigPair { file, config } )
465
468
}
466
469
}
467
470
468
- fn format (
469
- opt : Opt ,
470
- ) -> Result < i32 > {
471
+ fn format ( opt : Opt ) -> Result < i32 > {
471
472
if opt. files . is_empty ( ) {
472
473
let mut buf = String :: new ( ) ;
473
474
stdin ( ) . read_to_string ( & mut buf) ?;
0 commit comments