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