1
+ use anyhow:: { format_err, Result } ;
1
2
use env_logger;
2
- use failure:: { err_msg, format_err, Error as FailureError , Fail } ;
3
3
use io:: Error as IoError ;
4
+ use thiserror:: Error ;
4
5
5
6
use rustfmt_nightly as rustfmt;
6
7
@@ -61,23 +62,23 @@ enum Operation {
61
62
}
62
63
63
64
/// Rustfmt operations errors.
64
- #[ derive( Fail , Debug ) ]
65
+ #[ derive( Error , Debug ) ]
65
66
pub enum OperationError {
66
67
/// An unknown help topic was requested.
67
- #[ fail ( display = "Unknown help topic: `{}`." , _0 ) ]
68
+ #[ error ( "Unknown help topic: `{0 }`." ) ]
68
69
UnknownHelpTopic ( String ) ,
69
70
/// An unknown print-config option was requested.
70
- #[ fail ( display = "Unknown print-config option: `{}`." , _0 ) ]
71
+ #[ error ( "Unknown print-config option: `{0 }`." ) ]
71
72
UnknownPrintConfigTopic ( String ) ,
72
73
/// Attempt to generate a minimal config from standard input.
73
- #[ fail ( display = "The `--print-config=minimal` option doesn't work with standard input." ) ]
74
+ #[ error ( "The `--print-config=minimal` option doesn't work with standard input." ) ]
74
75
MinimalPathWithStdin ,
75
76
/// An io error during reading or writing.
76
- #[ fail ( display = "io error: {}" , _0 ) ]
77
+ #[ error ( "io error: {0}" ) ]
77
78
IoError ( IoError ) ,
78
79
/// Attempt to use --emit with a mode which is not currently
79
80
/// supported with stdandard input.
80
- #[ fail ( display = "Emit mode {} not supported with standard output." , _0 ) ]
81
+ #[ error ( "Emit mode {0 } not supported with standard output." ) ]
81
82
StdinBadEmit ( EmitMode ) ,
82
83
}
83
84
@@ -189,7 +190,7 @@ fn is_nightly() -> bool {
189
190
}
190
191
191
192
// Returned i32 is an exit code
192
- fn execute ( opts : & Options ) -> Result < i32 , FailureError > {
193
+ fn execute ( opts : & Options ) -> Result < i32 > {
193
194
let matches = opts. parse ( env:: args ( ) . skip ( 1 ) ) ?;
194
195
let options = GetOptsOptions :: from_matches ( & matches) ?;
195
196
@@ -211,7 +212,7 @@ fn execute(opts: &Options) -> Result<i32, FailureError> {
211
212
Ok ( 0 )
212
213
}
213
214
Operation :: ConfigOutputDefault { path } => {
214
- let toml = Config :: default ( ) . all_options ( ) . to_toml ( ) . map_err ( err_msg ) ?;
215
+ let toml = Config :: default ( ) . all_options ( ) . to_toml ( ) ?;
215
216
if let Some ( path) = path {
216
217
let mut file = File :: create ( path) ?;
217
218
file. write_all ( toml. as_bytes ( ) ) ?;
@@ -230,7 +231,7 @@ fn execute(opts: &Options) -> Result<i32, FailureError> {
230
231
let file = file. canonicalize ( ) . unwrap_or ( file) ;
231
232
232
233
let ( config, _) = load_config ( Some ( file. parent ( ) . unwrap ( ) ) , Some ( options. clone ( ) ) ) ?;
233
- let toml = config. all_options ( ) . to_toml ( ) . map_err ( err_msg ) ?;
234
+ let toml = config. all_options ( ) . to_toml ( ) ?;
234
235
io:: stdout ( ) . write_all ( toml. as_bytes ( ) ) ?;
235
236
236
237
Ok ( 0 )
@@ -243,7 +244,7 @@ fn execute(opts: &Options) -> Result<i32, FailureError> {
243
244
}
244
245
}
245
246
246
- fn format_string ( input : String , options : GetOptsOptions ) -> Result < i32 , FailureError > {
247
+ fn format_string ( input : String , options : GetOptsOptions ) -> Result < i32 > {
247
248
// try to read config from local directory
248
249
let ( mut config, _) = load_config ( Some ( Path :: new ( "." ) ) , Some ( options. clone ( ) ) ) ?;
249
250
@@ -289,7 +290,7 @@ fn format(
289
290
files : Vec < PathBuf > ,
290
291
minimal_config_path : Option < String > ,
291
292
options : & GetOptsOptions ,
292
- ) -> Result < i32 , FailureError > {
293
+ ) -> Result < i32 > {
293
294
options. verify_file_lines ( & files) ;
294
295
let ( config, config_path) = load_config ( None , Some ( options. clone ( ) ) ) ?;
295
296
@@ -337,7 +338,7 @@ fn format(
337
338
// that were used during formatting as TOML.
338
339
if let Some ( path) = minimal_config_path {
339
340
let mut file = File :: create ( path) ?;
340
- let toml = session. config . used_options ( ) . to_toml ( ) . map_err ( err_msg ) ?;
341
+ let toml = session. config . used_options ( ) . to_toml ( ) ?;
341
342
file. write_all ( toml. as_bytes ( ) ) ?;
342
343
}
343
344
@@ -521,7 +522,7 @@ fn deprecate_skip_children() {
521
522
}
522
523
523
524
impl GetOptsOptions {
524
- pub fn from_matches ( matches : & Matches ) -> Result < GetOptsOptions , FailureError > {
525
+ pub fn from_matches ( matches : & Matches ) -> Result < GetOptsOptions > {
525
526
let mut options = GetOptsOptions :: default ( ) ;
526
527
options. verbose = matches. opt_present ( "verbose" ) ;
527
528
options. quiet = matches. opt_present ( "quiet" ) ;
@@ -543,7 +544,7 @@ impl GetOptsOptions {
543
544
options. error_on_unformatted = Some ( true ) ;
544
545
}
545
546
if let Some ( ref file_lines) = matches. opt_str ( "file-lines" ) {
546
- options. file_lines = file_lines. parse ( ) . map_err ( err_msg ) ?;
547
+ options. file_lines = file_lines. parse ( ) ?;
547
548
}
548
549
} else {
549
550
let mut unstable_options = vec ! [ ] ;
@@ -686,15 +687,15 @@ impl CliOptions for GetOptsOptions {
686
687
}
687
688
}
688
689
689
- fn edition_from_edition_str ( edition_str : & str ) -> Result < Edition , FailureError > {
690
+ fn edition_from_edition_str ( edition_str : & str ) -> Result < Edition > {
690
691
match edition_str {
691
692
"2015" => Ok ( Edition :: Edition2015 ) ,
692
693
"2018" => Ok ( Edition :: Edition2018 ) ,
693
694
_ => Err ( format_err ! ( "Invalid value for `--edition`" ) ) ,
694
695
}
695
696
}
696
697
697
- fn emit_mode_from_emit_str ( emit_str : & str ) -> Result < EmitMode , FailureError > {
698
+ fn emit_mode_from_emit_str ( emit_str : & str ) -> Result < EmitMode > {
698
699
match emit_str {
699
700
"files" => Ok ( EmitMode :: Files ) ,
700
701
"stdout" => Ok ( EmitMode :: Stdout ) ,
0 commit comments