@@ -9,9 +9,10 @@ use rustc_lint_defs::Applicability;
9
9
use rustc_serialize:: json:: Json ;
10
10
use rustc_span:: { MultiSpan , Span , DUMMY_SP } ;
11
11
use std:: fmt;
12
+ use std:: hash:: { Hash , Hasher } ;
12
13
13
14
#[ must_use]
14
- #[ derive( Clone , Debug , PartialEq , Hash , Encodable , Decodable ) ]
15
+ #[ derive( Clone , Debug , Encodable , Decodable ) ]
15
16
pub struct Diagnostic {
16
17
pub level : Level ,
17
18
pub message : Vec < ( String , Style ) > ,
@@ -24,6 +25,10 @@ pub struct Diagnostic {
24
25
/// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of
25
26
/// `span` if there is one. Otherwise, it is `DUMMY_SP`.
26
27
pub sort_span : Span ,
28
+
29
+ /// If diagnostic is from Lint, custom hash function ignores notes
30
+ /// otherwise hash is based on the all the fields
31
+ pub is_lint : bool ,
27
32
}
28
33
29
34
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Encodable , Decodable ) ]
@@ -91,6 +96,7 @@ impl Diagnostic {
91
96
children : vec ! [ ] ,
92
97
suggestions : vec ! [ ] ,
93
98
sort_span : DUMMY_SP ,
99
+ is_lint : false ,
94
100
}
95
101
}
96
102
@@ -558,6 +564,11 @@ impl Diagnostic {
558
564
self
559
565
}
560
566
567
+ pub fn set_is_lint ( & mut self ) -> & mut Self {
568
+ self . is_lint = true ;
569
+ self
570
+ }
571
+
561
572
pub fn code ( & mut self , s : DiagnosticId ) -> & mut Self {
562
573
self . code = Some ( s) ;
563
574
self
@@ -617,6 +628,42 @@ impl Diagnostic {
617
628
let sub = SubDiagnostic { level, message, span, render_span } ;
618
629
self . children . push ( sub) ;
619
630
}
631
+
632
+ /// Fields used for Hash, and PartialEq trait
633
+ fn keys (
634
+ & self ,
635
+ ) -> (
636
+ & Level ,
637
+ & Vec < ( String , Style ) > ,
638
+ & Option < DiagnosticId > ,
639
+ & MultiSpan ,
640
+ & Vec < CodeSuggestion > ,
641
+ Option < & Vec < SubDiagnostic > > ,
642
+ ) {
643
+ (
644
+ & self . level ,
645
+ & self . message ,
646
+ & self . code ,
647
+ & self . span ,
648
+ & self . suggestions ,
649
+ ( if self . is_lint { None } else { Some ( & self . children ) } ) ,
650
+ )
651
+ }
652
+ }
653
+
654
+ impl Hash for Diagnostic {
655
+ fn hash < H > ( & self , state : & mut H )
656
+ where
657
+ H : Hasher ,
658
+ {
659
+ self . keys ( ) . hash ( state) ;
660
+ }
661
+ }
662
+
663
+ impl PartialEq for Diagnostic {
664
+ fn eq ( & self , other : & Self ) -> bool {
665
+ self . keys ( ) == other. keys ( )
666
+ }
620
667
}
621
668
622
669
impl SubDiagnostic {
0 commit comments