about summary refs log tree commit diff
path: root/src/format-diff
diff options
context:
space:
mode:
authorTibo <delor.thibault@gmail.com>2018-04-24 15:45:28 +1000
committerTibo <delor.thibault@gmail.com>2018-04-26 12:18:20 +1000
commitefb8069cfc8b587994d842936b4d14d257f480c4 (patch)
treea2a64e4c293131b7ab0e0b95efefa97351180be5 /src/format-diff
parentac8ae0062544743aaea1719a34f299b66f2b7dc9 (diff)
downloadrust-efb8069cfc8b587994d842936b4d14d257f480c4.tar.gz
rust-efb8069cfc8b587994d842936b4d14d257f480c4.zip
Replace std::Error with failure for FormatDiff
Diffstat (limited to 'src/format-diff')
-rw-r--r--src/format-diff/main.rs38
1 files changed, 11 insertions, 27 deletions
diff --git a/src/format-diff/main.rs b/src/format-diff/main.rs
index 402f7ab507a..fe528a6c0ea 100644
--- a/src/format-diff/main.rs
+++ b/src/format-diff/main.rs
@@ -15,6 +15,8 @@
 #![deny(warnings)]
 
 extern crate env_logger;
+#[macro_use]
+extern crate failure;
 extern crate getopts;
 #[macro_use]
 extern crate log;
@@ -24,9 +26,8 @@ extern crate serde_derive;
 extern crate serde_json as json;
 
 use std::collections::HashSet;
-use std::error::Error;
 use std::io::{self, BufRead};
-use std::{env, fmt, process};
+use std::{env, process};
 
 use regex::Regex;
 
@@ -35,31 +36,14 @@ use regex::Regex;
 /// We only want to format rust files by default.
 const DEFAULT_PATTERN: &str = r".*\.rs";
 
-#[derive(Debug)]
+#[derive(Fail, Debug)]
 enum FormatDiffError {
-    IncorrectOptions(getopts::Fail),
-    IncorrectFilter(regex::Error),
-    IoError(io::Error),
-}
-
-impl fmt::Display for FormatDiffError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
-        fmt::Display::fmt(self.cause().unwrap(), f)
-    }
-}
-
-impl Error for FormatDiffError {
-    fn description(&self) -> &str {
-        self.cause().unwrap().description()
-    }
-
-    fn cause(&self) -> Option<&Error> {
-        Some(match *self {
-            FormatDiffError::IoError(ref e) => e,
-            FormatDiffError::IncorrectFilter(ref e) => e,
-            FormatDiffError::IncorrectOptions(ref e) => e,
-        })
-    }
+    #[fail(display = "{}", _0)]
+    IncorrectOptions(#[cause] getopts::Fail),
+    #[fail(display = "{}", _0)]
+    IncorrectFilter(#[cause] regex::Error),
+    #[fail(display = "{}", _0)]
+    IoError(#[cause] io::Error),
 }
 
 impl From<getopts::Fail> for FormatDiffError {
@@ -99,7 +83,7 @@ fn main() {
     );
 
     if let Err(e) = run(&opts) {
-        println!("{}", opts.usage(e.description()));
+        println!("{}", opts.usage(&format!("{}", e)));
         process::exit(1);
     }
 }