@@ -200,27 +200,58 @@ impl FormattingError {
200
200
#[ derive( Clone ) ]
201
201
pub struct FormatReport {
202
202
// Maps stringified file paths to their associated formatting errors.
203
- file_error_map : Rc < RefCell < HashMap < FileName , Vec < FormattingError > > > > ,
203
+ internal : Rc < RefCell < ( FormatErrorMap , ReportedErrors ) > > ,
204
+ }
205
+
206
+ type FormatErrorMap = HashMap < FileName , Vec < FormattingError > > ;
207
+
208
+ #[ derive( Default , Debug ) ]
209
+ struct ReportedErrors {
210
+ has_operational_errors : bool ,
211
+ has_check_errors : bool ,
204
212
}
205
213
206
214
impl FormatReport {
207
215
fn new ( ) -> FormatReport {
208
216
FormatReport {
209
- file_error_map : Rc :: new ( RefCell :: new ( HashMap :: new ( ) ) ) ,
217
+ internal : Rc :: new ( RefCell :: new ( ( HashMap :: new ( ) , ReportedErrors :: default ( ) ) ) ) ,
210
218
}
211
219
}
212
220
213
221
fn append ( & self , f : FileName , mut v : Vec < FormattingError > ) {
214
- self . file_error_map
222
+ self . track_errors ( & v) ;
223
+ self . internal
215
224
. borrow_mut ( )
225
+ . 0
216
226
. entry ( f)
217
227
. and_modify ( |fe| fe. append ( & mut v) )
218
228
. or_insert ( v) ;
219
229
}
220
230
231
+ fn track_errors ( & self , new_errors : & [ FormattingError ] ) {
232
+ let errs = & mut self . internal . borrow_mut ( ) . 1 ;
233
+ if errs. has_operational_errors && errs. has_check_errors {
234
+ return ;
235
+ }
236
+ for err in new_errors {
237
+ match err. kind {
238
+ ErrorKind :: LineOverflow ( ..) | ErrorKind :: TrailingWhitespace => {
239
+ errs. has_operational_errors = true ;
240
+ }
241
+ ErrorKind :: BadIssue ( _)
242
+ | ErrorKind :: LicenseCheck
243
+ | ErrorKind :: DeprecatedAttr
244
+ | ErrorKind :: BadAttr => {
245
+ errs. has_check_errors = true ;
246
+ }
247
+ }
248
+ }
249
+ }
250
+
221
251
fn warning_count ( & self ) -> usize {
222
- self . file_error_map
252
+ self . internal
223
253
. borrow ( )
254
+ . 0
224
255
. iter ( )
225
256
. map ( |( _, errors) | errors. len ( ) )
226
257
. sum ( )
@@ -234,7 +265,7 @@ impl FormatReport {
234
265
& self ,
235
266
mut t : Box < term:: Terminal < Output = io:: Stderr > > ,
236
267
) -> Result < ( ) , term:: Error > {
237
- for ( file, errors) in & * self . file_error_map . borrow ( ) {
268
+ for ( file, errors) in & self . internal . borrow ( ) . 0 {
238
269
for error in errors {
239
270
let prefix_space_len = error. line . to_string ( ) . len ( ) ;
240
271
let prefix_spaces = " " . repeat ( 1 + prefix_space_len) ;
@@ -280,7 +311,7 @@ impl FormatReport {
280
311
}
281
312
}
282
313
283
- if !self . file_error_map . borrow ( ) . is_empty ( ) {
314
+ if !self . internal . borrow ( ) . 0 . is_empty ( ) {
284
315
t. attr ( term:: Attr :: Bold ) ?;
285
316
write ! ( t, "warning: " ) ?;
286
317
t. reset ( ) ?;
@@ -304,7 +335,7 @@ fn target_str(space_len: usize, target_len: usize) -> String {
304
335
impl fmt:: Display for FormatReport {
305
336
// Prints all the formatting errors.
306
337
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> Result < ( ) , fmt:: Error > {
307
- for ( file, errors) in & * self . file_error_map . borrow ( ) {
338
+ for ( file, errors) in & self . internal . borrow ( ) . 0 {
308
339
for error in errors {
309
340
let prefix_space_len = error. line . to_string ( ) . len ( ) ;
310
341
let prefix_spaces = " " . repeat ( 1 + prefix_space_len) ;
@@ -343,7 +374,7 @@ impl fmt::Display for FormatReport {
343
374
) ?;
344
375
}
345
376
}
346
- if !self . file_error_map . borrow ( ) . is_empty ( ) {
377
+ if !self . internal . borrow ( ) . 0 . is_empty ( ) {
347
378
writeln ! (
348
379
fmt,
349
380
"warning: rustfmt may have failed to format. See previous {} errors." ,
@@ -827,6 +858,16 @@ fn format_input_inner<T: Write>(
827
858
)
828
859
} ) ;
829
860
861
+ {
862
+ let report_errs = & report. internal . borrow ( ) . 1 ;
863
+ if report_errs. has_check_errors {
864
+ summary. add_check_error ( ) ;
865
+ }
866
+ if report_errs. has_operational_errors {
867
+ summary. add_operational_error ( ) ;
868
+ }
869
+ }
870
+
830
871
match format_result {
831
872
Ok ( ( file_map, has_diff) ) => {
832
873
if report. has_warnings ( ) {
0 commit comments