Skip to content

Commit 2fbda8a

Browse files
committed
Remove parents from diagnostic hashing.
1 parent e7618cf commit 2fbda8a

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

compiler/rustc_error_messages/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,17 @@ impl MultiSpan {
511511
pub fn clone_ignoring_labels(&self) -> Self {
512512
Self { primary_spans: self.primary_spans.clone(), ..MultiSpan::new() }
513513
}
514+
515+
pub fn clone_ignoring_parents(&self) -> Self {
516+
Self {
517+
primary_spans: self.primary_spans.iter().map(|s| s.with_parent(None)).collect(),
518+
span_labels: self
519+
.span_labels
520+
.iter()
521+
.map(|(s, l)| (s.with_parent(None), l.clone()))
522+
.collect(),
523+
}
524+
}
514525
}
515526

516527
impl From<Span> for MultiSpan {

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,19 +403,28 @@ impl DiagInner {
403403
&Level,
404404
&[(DiagMessage, Style)],
405405
&Option<ErrCode>,
406-
&MultiSpan,
407-
&[Subdiag],
408-
&Suggestions,
406+
MultiSpan,
407+
Vec<Subdiag>,
408+
Suggestions,
409409
Vec<(&DiagArgName, &DiagArgValue)>,
410410
&Option<IsLint>,
411411
) {
412+
let suggestions = match &self.suggestions {
413+
Suggestions::Enabled(sugg) => Suggestions::Enabled(
414+
sugg.iter().map(CodeSuggestion::clone_ignoring_parents).collect(),
415+
),
416+
Suggestions::Sealed(sugg) => Suggestions::Sealed(
417+
sugg.iter().map(CodeSuggestion::clone_ignoring_parents).collect(),
418+
),
419+
Suggestions::Disabled => Suggestions::Disabled,
420+
};
412421
(
413422
&self.level,
414423
&self.messages,
415424
&self.code,
416-
&self.span,
417-
&self.children,
418-
&self.suggestions,
425+
self.span.clone_ignoring_parents(),
426+
self.children.iter().map(Subdiag::clone_ignoring_parents).collect(),
427+
suggestions,
419428
self.args.iter().collect(),
420429
// omit self.sort_span
421430
&self.is_lint,
@@ -448,6 +457,13 @@ pub struct Subdiag {
448457
pub span: MultiSpan,
449458
}
450459

460+
impl Subdiag {
461+
fn clone_ignoring_parents(&self) -> Subdiag {
462+
let Subdiag { level, messages, span } = self;
463+
Subdiag { level: *level, messages: messages.clone(), span: span.clone_ignoring_parents() }
464+
}
465+
}
466+
451467
/// Used for emitting structured error messages and other diagnostic information.
452468
/// Wraps a `DiagInner`, adding some useful things.
453469
/// - The `dcx` field, allowing it to (a) emit itself, and (b) do a drop check

compiler/rustc_errors/src/lib.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,29 @@ impl SubstitutionPart {
233233
sm.span_to_snippet(self.span)
234234
.map_or(!self.span.is_empty(), |snippet| !snippet.trim().is_empty())
235235
}
236+
237+
fn clone_ignoring_parents(&self) -> SubstitutionPart {
238+
let SubstitutionPart { span, snippet } = self;
239+
SubstitutionPart { span: span.with_parent(None), snippet: snippet.clone() }
240+
}
236241
}
237242

238243
impl CodeSuggestion {
244+
pub fn clone_ignoring_parents(&self) -> CodeSuggestion {
245+
let CodeSuggestion { substitutions, msg, style, applicability } = self;
246+
CodeSuggestion {
247+
substitutions: substitutions
248+
.iter()
249+
.map(|Substitution { parts }| Substitution {
250+
parts: parts.iter().map(SubstitutionPart::clone_ignoring_parents).collect(),
251+
})
252+
.collect(),
253+
msg: msg.clone(),
254+
style: *style,
255+
applicability: *applicability,
256+
}
257+
}
258+
239259
/// Returns the assembled code suggestions, whether they should be shown with an underline
240260
/// and whether the substitution only differs in capitalization.
241261
pub(crate) fn splice_lines(
@@ -1533,6 +1553,7 @@ impl DiagCtxtInner {
15331553
let mut hasher = StableHasher::new();
15341554
diagnostic.hash(&mut hasher);
15351555
let diagnostic_hash = hasher.finish();
1556+
debug!(?diagnostic, ?diagnostic_hash);
15361557
!self.emitted_diagnostics.insert(diagnostic_hash)
15371558
};
15381559

@@ -1542,18 +1563,14 @@ impl DiagCtxtInner {
15421563
// Only emit the diagnostic if we've been asked to deduplicate or
15431564
// haven't already emitted an equivalent diagnostic.
15441565
if !(self.flags.deduplicate_diagnostics && already_emitted) {
1545-
debug!(?diagnostic);
1546-
debug!(?self.emitted_diagnostics);
1547-
15481566
let already_emitted_sub = |sub: &mut Subdiag| {
1549-
debug!(?sub);
15501567
if sub.level != OnceNote && sub.level != OnceHelp {
15511568
return false;
15521569
}
15531570
let mut hasher = StableHasher::new();
15541571
sub.hash(&mut hasher);
15551572
let diagnostic_hash = hasher.finish();
1556-
debug!(?diagnostic_hash);
1573+
debug!(?sub, ?diagnostic_hash);
15571574
!self.emitted_diagnostics.insert(diagnostic_hash)
15581575
};
15591576
diagnostic.children.extract_if(already_emitted_sub).for_each(|_| {});

0 commit comments

Comments
 (0)