1+ use anyhow:: { format_err, Result } ;
12use env_logger;
2- use failure:: { err_msg, format_err, Error as FailureError , Fail } ;
33use io:: Error as IoError ;
4+ use thiserror:: Error ;
45
56use rustfmt_nightly as rustfmt;
67
@@ -61,23 +62,23 @@ enum Operation {
6162}
6263
6364/// Rustfmt operations errors.
64- #[ derive( Fail , Debug ) ]
65+ #[ derive( Error , Debug ) ]
6566pub enum OperationError {
6667 /// An unknown help topic was requested.
67- #[ fail ( display = "Unknown help topic: `{}`." , _0 ) ]
68+ #[ error ( "Unknown help topic: `{0 }`." ) ]
6869 UnknownHelpTopic ( String ) ,
6970 /// An unknown print-config option was requested.
70- #[ fail ( display = "Unknown print-config option: `{}`." , _0 ) ]
71+ #[ error ( "Unknown print-config option: `{0 }`." ) ]
7172 UnknownPrintConfigTopic ( String ) ,
7273 /// 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." ) ]
7475 MinimalPathWithStdin ,
7576 /// An io error during reading or writing.
76- #[ fail ( display = "io error: {}" , _0 ) ]
77+ #[ error ( "io error: {0}" ) ]
7778 IoError ( IoError ) ,
7879 /// Attempt to use --emit with a mode which is not currently
7980 /// 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." ) ]
8182 StdinBadEmit ( EmitMode ) ,
8283}
8384
@@ -189,7 +190,7 @@ fn is_nightly() -> bool {
189190}
190191
191192// Returned i32 is an exit code
192- fn execute ( opts : & Options ) -> Result < i32 , FailureError > {
193+ fn execute ( opts : & Options ) -> Result < i32 > {
193194 let matches = opts. parse ( env:: args ( ) . skip ( 1 ) ) ?;
194195 let options = GetOptsOptions :: from_matches ( & matches) ?;
195196
@@ -211,7 +212,7 @@ fn execute(opts: &Options) -> Result<i32, FailureError> {
211212 Ok ( 0 )
212213 }
213214 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 ( ) ?;
215216 if let Some ( path) = path {
216217 let mut file = File :: create ( path) ?;
217218 file. write_all ( toml. as_bytes ( ) ) ?;
@@ -230,7 +231,7 @@ fn execute(opts: &Options) -> Result<i32, FailureError> {
230231 let file = file. canonicalize ( ) . unwrap_or ( file) ;
231232
232233 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 ( ) ?;
234235 io:: stdout ( ) . write_all ( toml. as_bytes ( ) ) ?;
235236
236237 Ok ( 0 )
@@ -243,7 +244,7 @@ fn execute(opts: &Options) -> Result<i32, FailureError> {
243244 }
244245}
245246
246- fn format_string ( input : String , options : GetOptsOptions ) -> Result < i32 , FailureError > {
247+ fn format_string ( input : String , options : GetOptsOptions ) -> Result < i32 > {
247248 // try to read config from local directory
248249 let ( mut config, _) = load_config ( Some ( Path :: new ( "." ) ) , Some ( options. clone ( ) ) ) ?;
249250
@@ -289,7 +290,7 @@ fn format(
289290 files : Vec < PathBuf > ,
290291 minimal_config_path : Option < String > ,
291292 options : & GetOptsOptions ,
292- ) -> Result < i32 , FailureError > {
293+ ) -> Result < i32 > {
293294 options. verify_file_lines ( & files) ;
294295 let ( config, config_path) = load_config ( None , Some ( options. clone ( ) ) ) ?;
295296
@@ -337,7 +338,7 @@ fn format(
337338 // that were used during formatting as TOML.
338339 if let Some ( path) = minimal_config_path {
339340 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 ( ) ?;
341342 file. write_all ( toml. as_bytes ( ) ) ?;
342343 }
343344
@@ -521,7 +522,7 @@ fn deprecate_skip_children() {
521522}
522523
523524impl GetOptsOptions {
524- pub fn from_matches ( matches : & Matches ) -> Result < GetOptsOptions , FailureError > {
525+ pub fn from_matches ( matches : & Matches ) -> Result < GetOptsOptions > {
525526 let mut options = GetOptsOptions :: default ( ) ;
526527 options. verbose = matches. opt_present ( "verbose" ) ;
527528 options. quiet = matches. opt_present ( "quiet" ) ;
@@ -543,7 +544,7 @@ impl GetOptsOptions {
543544 options. error_on_unformatted = Some ( true ) ;
544545 }
545546 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 ( ) ?;
547548 }
548549 } else {
549550 let mut unstable_options = vec ! [ ] ;
@@ -686,15 +687,15 @@ impl CliOptions for GetOptsOptions {
686687 }
687688}
688689
689- fn edition_from_edition_str ( edition_str : & str ) -> Result < Edition , FailureError > {
690+ fn edition_from_edition_str ( edition_str : & str ) -> Result < Edition > {
690691 match edition_str {
691692 "2015" => Ok ( Edition :: Edition2015 ) ,
692693 "2018" => Ok ( Edition :: Edition2018 ) ,
693694 _ => Err ( format_err ! ( "Invalid value for `--edition`" ) ) ,
694695 }
695696}
696697
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 > {
698699 match emit_str {
699700 "files" => Ok ( EmitMode :: Files ) ,
700701 "stdout" => Ok ( EmitMode :: Stdout ) ,
0 commit comments