@@ -35,9 +35,9 @@ bitflags! {
35
35
}
36
36
37
37
#[ derive( Serialize ) ]
38
- struct ExpandedStatistics < ' a > {
38
+ struct ExpandedStatistics {
39
39
code : SerializeRuleAsCode ,
40
- message : & ' a str ,
40
+ name : SerializeRuleAsTitle ,
41
41
count : usize ,
42
42
fixable : bool ,
43
43
}
@@ -65,6 +65,29 @@ impl From<Rule> for SerializeRuleAsCode {
65
65
}
66
66
}
67
67
68
+ struct SerializeRuleAsTitle ( Rule ) ;
69
+
70
+ impl Serialize for SerializeRuleAsTitle {
71
+ fn serialize < S > ( & self , serializer : S ) -> std:: result:: Result < S :: Ok , S :: Error >
72
+ where
73
+ S : serde:: Serializer ,
74
+ {
75
+ serializer. serialize_str ( self . 0 . as_ref ( ) )
76
+ }
77
+ }
78
+
79
+ impl Display for SerializeRuleAsTitle {
80
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
81
+ write ! ( f, "{}" , self . 0 . as_ref( ) )
82
+ }
83
+ }
84
+
85
+ impl From < Rule > for SerializeRuleAsTitle {
86
+ fn from ( rule : Rule ) -> Self {
87
+ Self ( rule)
88
+ }
89
+ }
90
+
68
91
pub ( crate ) struct Printer {
69
92
format : SerializationFormat ,
70
93
log_level : LogLevel ,
@@ -313,29 +336,23 @@ impl Printer {
313
336
let statistics: Vec < ExpandedStatistics > = diagnostics
314
337
. messages
315
338
. iter ( )
316
- . map ( |message| {
317
- (
318
- message. kind . rule ( ) ,
319
- & message. kind . body ,
320
- message. fix . is_some ( ) ,
321
- )
322
- } )
339
+ . map ( |message| ( message. kind . rule ( ) , message. fix . is_some ( ) ) )
323
340
. sorted ( )
324
- . fold ( vec ! [ ] , |mut acc, ( rule, body , fixable) | {
325
- if let Some ( ( prev_rule, _, _ , count) ) = acc. last_mut ( ) {
341
+ . fold ( vec ! [ ] , |mut acc, ( rule, fixable) | {
342
+ if let Some ( ( prev_rule, _, count) ) = acc. last_mut ( ) {
326
343
if * prev_rule == rule {
327
344
* count += 1 ;
328
345
return acc;
329
346
}
330
347
}
331
- acc. push ( ( rule, body , fixable, 1 ) ) ;
348
+ acc. push ( ( rule, fixable, 1 ) ) ;
332
349
acc
333
350
} )
334
351
. iter ( )
335
- . map ( |( rule, message , fixable, count) | ExpandedStatistics {
352
+ . map ( |( rule, fixable, count) | ExpandedStatistics {
336
353
code : ( * rule) . into ( ) ,
354
+ name : ( * rule) . into ( ) ,
337
355
count : * count,
338
- message,
339
356
fixable : * fixable,
340
357
} )
341
358
. sorted_by_key ( |statistic| Reverse ( statistic. count ) )
@@ -384,7 +401,7 @@ impl Printer {
384
401
} else {
385
402
""
386
403
} ,
387
- statistic. message ,
404
+ statistic. name ,
388
405
) ?;
389
406
}
390
407
return Ok ( ( ) ) ;
0 commit comments