Add a note to duplicate diagnostics

This commit is contained in:
Alex Macleod 2023-10-04 18:34:50 +00:00
parent 2ffeb4636b
commit 5453a9f34d
166 changed files with 460 additions and 203 deletions

View file

@ -1376,16 +1376,16 @@ impl HandlerInner {
self.emitted_diagnostic_codes.insert(code.clone());
}
let already_emitted = |this: &mut Self| {
let already_emitted = {
let mut hasher = StableHasher::new();
diagnostic.hash(&mut hasher);
let diagnostic_hash = hasher.finish();
!this.emitted_diagnostics.insert(diagnostic_hash)
!self.emitted_diagnostics.insert(diagnostic_hash)
};
// Only emit the diagnostic if we've been asked to deduplicate or
// haven't already emitted an equivalent diagnostic.
if !(self.flags.deduplicate_diagnostics && already_emitted(self)) {
if !(self.flags.deduplicate_diagnostics && already_emitted) {
debug!(?diagnostic);
debug!(?self.emitted_diagnostics);
let already_emitted_sub = |sub: &mut SubDiagnostic| {
@ -1401,6 +1401,11 @@ impl HandlerInner {
};
diagnostic.children.extract_if(already_emitted_sub).for_each(|_| {});
if already_emitted {
diagnostic.note(
"duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`",
);
}
self.emitter.emit_diagnostic(diagnostic);
if diagnostic.is_error() {