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
@@ -59,27 +60,27 @@ enum Operation {
5960}
6061
6162/// Rustfmt operations errors.
62- #[ derive( Fail , Debug ) ]
63+ #[ derive( Error , Debug ) ]
6364pub enum OperationError {
6465 /// An unknown help topic was requested.
65- #[ fail ( display = "Unknown help topic: `{}`." , _0 ) ]
66+ #[ error ( "Unknown help topic: `{0 }`." ) ]
6667 UnknownHelpTopic ( String ) ,
6768 /// An unknown print-config option was requested.
68- #[ fail ( display = "Unknown print-config option: `{}`." , _0 ) ]
69+ #[ error ( "Unknown print-config option: `{0 }`." ) ]
6970 UnknownPrintConfigTopic ( String ) ,
7071 /// Attempt to generate a minimal config from standard input.
71- #[ fail ( display = "The `--print-config=minimal` option doesn't work with standard input." ) ]
72+ #[ error ( "The `--print-config=minimal` option doesn't work with standard input." ) ]
7273 MinimalPathWithStdin ,
7374 /// An io error during reading or writing.
74- #[ fail ( display = "io error: {}" , _0 ) ]
75+ #[ error ( "{0}" ) ]
7576 IoError ( IoError ) ,
7677 /// Attempt to use --check with stdin, which isn't currently
7778 /// supported.
78- #[ fail ( display = "The `--check` option is not supported with standard input." ) ]
79+ #[ error ( "The `--check` option is not supported with standard input." ) ]
7980 CheckWithStdin ,
8081 /// Attempt to use --emit=json with stdin, which isn't currently
8182 /// supported.
82- #[ fail ( display = "Using `--emit` other than stdout is not supported with standard input." ) ]
83+ #[ error ( "Using `--emit` other than stdout is not supported with standard input." ) ]
8384 EmitWithStdin ,
8485}
8586
@@ -192,7 +193,7 @@ fn is_nightly() -> bool {
192193}
193194
194195// Returned i32 is an exit code
195- fn execute ( opts : & Options ) -> Result < i32 , FailureError > {
196+ fn execute ( opts : & Options ) -> Result < i32 > {
196197 let matches = opts. parse ( env:: args ( ) . skip ( 1 ) ) ?;
197198 let options = GetOptsOptions :: from_matches ( & matches) ?;
198199
@@ -214,7 +215,7 @@ fn execute(opts: &Options) -> Result<i32, FailureError> {
214215 Ok ( 0 )
215216 }
216217 Operation :: ConfigOutputDefault { path } => {
217- let toml = Config :: default ( ) . all_options ( ) . to_toml ( ) . map_err ( err_msg ) ?;
218+ let toml = Config :: default ( ) . all_options ( ) . to_toml ( ) ?;
218219 if let Some ( path) = path {
219220 let mut file = File :: create ( path) ?;
220221 file. write_all ( toml. as_bytes ( ) ) ?;
@@ -233,7 +234,7 @@ fn execute(opts: &Options) -> Result<i32, FailureError> {
233234 let file = file. canonicalize ( ) . unwrap_or ( file) ;
234235
235236 let ( config, _) = load_config ( Some ( file. parent ( ) . unwrap ( ) ) , Some ( options. clone ( ) ) ) ?;
236- let toml = config. all_options ( ) . to_toml ( ) . map_err ( err_msg ) ?;
237+ let toml = config. all_options ( ) . to_toml ( ) ?;
237238 io:: stdout ( ) . write_all ( toml. as_bytes ( ) ) ?;
238239
239240 Ok ( 0 )
@@ -246,7 +247,7 @@ fn execute(opts: &Options) -> Result<i32, FailureError> {
246247 }
247248}
248249
249- fn format_string ( input : String , options : GetOptsOptions ) -> Result < i32 , FailureError > {
250+ fn format_string ( input : String , options : GetOptsOptions ) -> Result < i32 > {
250251 // try to read config from local directory
251252 let ( mut config, _) = load_config ( Some ( Path :: new ( "." ) ) , Some ( options. clone ( ) ) ) ?;
252253
@@ -287,7 +288,7 @@ fn format(
287288 files : Vec < PathBuf > ,
288289 minimal_config_path : Option < String > ,
289290 options : & GetOptsOptions ,
290- ) -> Result < i32 , FailureError > {
291+ ) -> Result < i32 > {
291292 options. verify_file_lines ( & files) ;
292293 let ( config, config_path) = load_config ( None , Some ( options. clone ( ) ) ) ?;
293294
@@ -335,7 +336,7 @@ fn format(
335336 // that were used during formatting as TOML.
336337 if let Some ( path) = minimal_config_path {
337338 let mut file = File :: create ( path) ?;
338- let toml = session. config . used_options ( ) . to_toml ( ) . map_err ( err_msg ) ?;
339+ let toml = session. config . used_options ( ) . to_toml ( ) ?;
339340 file. write_all ( toml. as_bytes ( ) ) ?;
340341 }
341342
@@ -514,7 +515,7 @@ struct GetOptsOptions {
514515}
515516
516517impl GetOptsOptions {
517- pub fn from_matches ( matches : & Matches ) -> Result < GetOptsOptions , FailureError > {
518+ pub fn from_matches ( matches : & Matches ) -> Result < GetOptsOptions > {
518519 let mut options = GetOptsOptions :: default ( ) ;
519520 options. verbose = matches. opt_present ( "verbose" ) ;
520521 options. quiet = matches. opt_present ( "quiet" ) ;
@@ -535,7 +536,7 @@ impl GetOptsOptions {
535536 options. error_on_unformatted = Some ( true ) ;
536537 }
537538 if let Some ( ref file_lines) = matches. opt_str ( "file-lines" ) {
538- options. file_lines = file_lines. parse ( ) . map_err ( err_msg ) ?;
539+ options. file_lines = file_lines. parse ( ) ?;
539540 }
540541 } else {
541542 let mut unstable_options = vec ! [ ] ;
@@ -684,15 +685,15 @@ impl CliOptions for GetOptsOptions {
684685 }
685686}
686687
687- fn edition_from_edition_str ( edition_str : & str ) -> Result < Edition , FailureError > {
688+ fn edition_from_edition_str ( edition_str : & str ) -> Result < Edition > {
688689 match edition_str {
689690 "2015" => Ok ( Edition :: Edition2015 ) ,
690691 "2018" => Ok ( Edition :: Edition2018 ) ,
691692 _ => Err ( format_err ! ( "Invalid value for `--edition`" ) ) ,
692693 }
693694}
694695
695- fn emit_mode_from_emit_str ( emit_str : & str ) -> Result < EmitMode , FailureError > {
696+ fn emit_mode_from_emit_str ( emit_str : & str ) -> Result < EmitMode > {
696697 match emit_str {
697698 "files" => Ok ( EmitMode :: Files ) ,
698699 "stdout" => Ok ( EmitMode :: Stdout ) ,
0 commit comments