Skip to content

Commit 5581be2

Browse files
committed
Use failure for FormattingError
1 parent efb8069 commit 5581be2

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/lib.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#[macro_use]
2020
extern crate derive_new;
2121
extern crate diff;
22+
extern crate failure;
2223
extern crate getopts;
2324
extern crate itertools;
2425
#[cfg(test)]
@@ -53,6 +54,7 @@ use syntax::errors::{DiagnosticBuilder, Handler};
5354
use syntax::parse::{self, ParseSess};
5455

5556
use comment::{CharClasses, FullCodeCharKind, LineClasses};
57+
use failure::Fail;
5658
use issues::{BadIssueSeeker, Issue};
5759
use shape::Indent;
5860
use utils::use_colored_tty;
@@ -109,33 +111,26 @@ pub(crate) type FileMap = Vec<FileRecord>;
109111

110112
pub(crate) type FileRecord = (FileName, String);
111113

112-
#[derive(Clone, Copy)]
114+
#[derive(Fail, Debug, Clone, Copy)]
113115
pub enum ErrorKind {
114116
// 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+
)]
115122
LineOverflow(usize, usize),
116123
// Line ends in whitespace
124+
#[fail(display = "left behind trailing whitespace")]
117125
TrailingWhitespace,
118126
// TODO or FIXME item without an issue number
127+
#[fail(display = "found {}", _0)]
119128
BadIssue(Issue),
120129
// License check has failed
130+
#[fail(display = "license check failed")]
121131
LicenseCheck,
122132
}
123133

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-
139134
// Formatting errors that are identified *after* rustfmt has run.
140135
struct FormattingError {
141136
line: usize,

0 commit comments

Comments
 (0)