|
19 | 19 | #[macro_use]
|
20 | 20 | extern crate derive_new;
|
21 | 21 | extern crate diff;
|
| 22 | +extern crate failure; |
22 | 23 | extern crate getopts;
|
23 | 24 | extern crate itertools;
|
24 | 25 | #[cfg(test)]
|
@@ -53,6 +54,7 @@ use syntax::errors::{DiagnosticBuilder, Handler};
|
53 | 54 | use syntax::parse::{self, ParseSess};
|
54 | 55 |
|
55 | 56 | use comment::{CharClasses, FullCodeCharKind, LineClasses};
|
| 57 | +use failure::Fail; |
56 | 58 | use issues::{BadIssueSeeker, Issue};
|
57 | 59 | use shape::Indent;
|
58 | 60 | use utils::use_colored_tty;
|
@@ -109,33 +111,26 @@ pub(crate) type FileMap = Vec<FileRecord>;
|
109 | 111 |
|
110 | 112 | pub(crate) type FileRecord = (FileName, String);
|
111 | 113 |
|
112 |
| -#[derive(Clone, Copy)] |
| 114 | +#[derive(Fail, Debug, Clone, Copy)] |
113 | 115 | pub enum ErrorKind {
|
114 | 116 | // Line has exceeded character limit (found, maximum)
|
| 117 | + #[fail( |
| 118 | + display = "line formatted, but exceeded maximum width (maximum: {} (see `max_width` option), found: {})", |
| 119 | + _0, |
| 120 | + _1 |
| 121 | + )] |
115 | 122 | LineOverflow(usize, usize),
|
116 | 123 | // Line ends in whitespace
|
| 124 | + #[fail(display = "left behind trailing whitespace")] |
117 | 125 | TrailingWhitespace,
|
118 | 126 | // TODO or FIXME item without an issue number
|
| 127 | + #[fail(display = "found {}", _0)] |
119 | 128 | BadIssue(Issue),
|
120 | 129 | // License check has failed
|
| 130 | + #[fail(display = "license check failed")] |
121 | 131 | LicenseCheck,
|
122 | 132 | }
|
123 | 133 |
|
124 |
| -impl fmt::Display for ErrorKind { |
125 |
| - fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { |
126 |
| - match *self { |
127 |
| - ErrorKind::LineOverflow(found, maximum) => write!( |
128 |
| - fmt, |
129 |
| - "line formatted, but exceeded maximum width (maximum: {} (see `max_width` option), found: {})", |
130 |
| - maximum, found, |
131 |
| - ), |
132 |
| - ErrorKind::TrailingWhitespace => write!(fmt, "left behind trailing whitespace"), |
133 |
| - ErrorKind::BadIssue(issue) => write!(fmt, "found {}", issue), |
134 |
| - ErrorKind::LicenseCheck => write!(fmt, "license check failed"), |
135 |
| - } |
136 |
| - } |
137 |
| -} |
138 |
| - |
139 | 134 | // Formatting errors that are identified *after* rustfmt has run.
|
140 | 135 | struct FormattingError {
|
141 | 136 | line: usize,
|
|
0 commit comments