|
1 | 1 | use std::borrow::Cow; |
2 | 2 | use std::fmt::{self, Debug}; |
3 | | -use std::hash::{Hash, Hasher}; |
| 3 | +use std::hash::Hash; |
4 | 4 | use std::ops::{Deref, DerefMut}; |
5 | 5 | use std::panic; |
6 | 6 | use std::path::PathBuf; |
7 | 7 | use std::thread::panicking; |
8 | 8 |
|
9 | 9 | use rustc_ast::attr::version::RustcVersion; |
10 | | -use rustc_error_messages::{DiagArgMap, DiagArgName, DiagArgValue, IntoDiagArg}; |
| 10 | +use rustc_data_structures::stable_hash::StableHasher; |
| 11 | +use rustc_error_messages::{DiagArgMap, DiagArgName, IntoDiagArg}; |
| 12 | +use rustc_hashes::Hash128; |
11 | 13 | use rustc_lint_defs::{Applicability, LintExpectationId}; |
12 | 14 | use rustc_macros::{Decodable, Encodable}; |
13 | 15 | use rustc_span::{DUMMY_SP, Span, Spanned, Symbol}; |
@@ -305,46 +307,31 @@ impl DiagInner { |
305 | 307 | } |
306 | 308 | } |
307 | 309 |
|
308 | | - /// Fields used for Hash, and PartialEq trait. |
309 | | - fn keys( |
310 | | - &self, |
311 | | - ) -> ( |
312 | | - &Level, |
313 | | - &[(DiagMessage, Style)], |
314 | | - &Option<ErrCode>, |
315 | | - &MultiSpan, |
316 | | - &[Subdiag], |
317 | | - &Suggestions, |
318 | | - Vec<(&DiagArgName, &DiagArgValue)>, |
319 | | - &Option<IsLint>, |
320 | | - ) { |
321 | | - ( |
322 | | - &self.level, |
323 | | - &self.messages, |
324 | | - &self.code, |
325 | | - &self.span, |
326 | | - &self.children, |
327 | | - &self.suggestions, |
328 | | - self.args.iter().collect(), |
329 | | - // omit self.sort_span |
330 | | - &self.is_lint, |
331 | | - // omit self.emitted_at |
332 | | - ) |
333 | | - } |
334 | | -} |
335 | | - |
336 | | -impl Hash for DiagInner { |
337 | | - fn hash<H>(&self, state: &mut H) |
338 | | - where |
339 | | - H: Hasher, |
340 | | - { |
341 | | - self.keys().hash(state); |
342 | | - } |
343 | | -} |
344 | | - |
345 | | -impl PartialEq for DiagInner { |
346 | | - fn eq(&self, other: &Self) -> bool { |
347 | | - self.keys() == other.keys() |
| 310 | + /// Hash used to determine if two diagnostics are the same. Used by |
| 311 | + /// `DiagCtxtInner::emitted_diagnostics`. Some fields are ignored for the hash. |
| 312 | + pub(crate) fn dedup_hash(&self) -> Hash128 { |
| 313 | + // Deconstruct to ensure all fields are considered. |
| 314 | + let DiagInner { |
| 315 | + level, |
| 316 | + messages, |
| 317 | + code, |
| 318 | + lint_id: _, // ignore |
| 319 | + span, |
| 320 | + children, |
| 321 | + suggestions, |
| 322 | + args, |
| 323 | + sort_span: _, // ignore |
| 324 | + is_lint, |
| 325 | + long_ty_path: _, // ignore |
| 326 | + emitted_at: _, // ignore |
| 327 | + } = self; |
| 328 | + |
| 329 | + let hashed_parts = |
| 330 | + (level, messages, code, span, children, suggestions, args.as_slice(), is_lint); |
| 331 | + |
| 332 | + let mut hasher = StableHasher::new(); |
| 333 | + hashed_parts.hash(&mut hasher); |
| 334 | + hasher.finish() |
348 | 335 | } |
349 | 336 | } |
350 | 337 |
|
|
0 commit comments