@@ -125,13 +125,13 @@ impl fmt::Display for ErrorKind {
125
125
match * self {
126
126
ErrorKind :: LineOverflow => {
127
127
write ! ( fmt, "line exceeded maximum length" )
128
- } ,
128
+ }
129
129
ErrorKind :: TrailingWhitespace => {
130
130
write ! ( fmt, "left behind trailing whitespace" )
131
- } ,
131
+ }
132
132
ErrorKind :: BadIssue ( issue) => {
133
133
write ! ( fmt, "found {}" , issue)
134
- } ,
134
+ }
135
135
}
136
136
}
137
137
}
@@ -142,6 +142,24 @@ struct FormattingError {
142
142
kind : ErrorKind ,
143
143
}
144
144
145
+ impl FormattingError {
146
+ fn msg_prefix ( & self ) -> & str {
147
+ match self . kind {
148
+ ErrorKind :: LineOverflow |
149
+ ErrorKind :: TrailingWhitespace => "Rustfmt failed at" ,
150
+ ErrorKind :: BadIssue ( _) => "WARNING:" ,
151
+ }
152
+ }
153
+
154
+ fn msg_suffix ( & self ) -> & str {
155
+ match self . kind {
156
+ ErrorKind :: LineOverflow |
157
+ ErrorKind :: TrailingWhitespace => "(sorry)" ,
158
+ ErrorKind :: BadIssue ( _) => "" ,
159
+ }
160
+ }
161
+ }
162
+
145
163
struct FormatReport {
146
164
// Maps stringified file paths to their associated formatting errors
147
165
file_error_map : HashMap < String , Vec < FormattingError > > ,
@@ -153,10 +171,12 @@ impl fmt::Display for FormatReport {
153
171
for ( file, errors) in self . file_error_map . iter ( ) {
154
172
for error in errors {
155
173
try!( write ! ( fmt,
156
- "Rustfmt failed at {}:{}: {} (sorry)\n " ,
174
+ "{} {}:{}: {} {}\n " ,
175
+ error. msg_prefix( ) ,
157
176
file,
158
177
error. line,
159
- error. kind) ) ;
178
+ error. kind,
179
+ error. msg_suffix( ) ) ) ;
160
180
}
161
181
}
162
182
Ok ( ( ) )
0 commit comments