@@ -9,9 +9,10 @@ use rustc_lint_defs::Applicability;
99use rustc_serialize:: json:: Json ;
1010use rustc_span:: { MultiSpan , Span , DUMMY_SP } ;
1111use std:: fmt;
12+ use std:: hash:: { Hash , Hasher } ;
1213
1314#[ must_use]
14- #[ derive( Clone , Debug , PartialEq , Hash , Encodable , Decodable ) ]
15+ #[ derive( Clone , Debug , Encodable , Decodable ) ]
1516pub struct Diagnostic {
1617 pub level : Level ,
1718 pub message : Vec < ( String , Style ) > ,
@@ -24,6 +25,10 @@ pub struct Diagnostic {
2425 /// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of
2526 /// `span` if there is one. Otherwise, it is `DUMMY_SP`.
2627 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 ,
2732}
2833
2934#[ derive( Clone , Debug , PartialEq , Eq , Hash , Encodable , Decodable ) ]
@@ -91,6 +96,7 @@ impl Diagnostic {
9196 children : vec ! [ ] ,
9297 suggestions : vec ! [ ] ,
9398 sort_span : DUMMY_SP ,
99+ is_lint : false ,
94100 }
95101 }
96102
@@ -558,6 +564,11 @@ impl Diagnostic {
558564 self
559565 }
560566
567+ pub fn set_is_lint ( & mut self ) -> & mut Self {
568+ self . is_lint = true ;
569+ self
570+ }
571+
561572 pub fn code ( & mut self , s : DiagnosticId ) -> & mut Self {
562573 self . code = Some ( s) ;
563574 self
@@ -617,6 +628,42 @@ impl Diagnostic {
617628 let sub = SubDiagnostic { level, message, span, render_span } ;
618629 self . children . push ( sub) ;
619630 }
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+ }
620667}
621668
622669impl SubDiagnostic {
0 commit comments