Skip to content

Commit 516b8e6

Browse files
committed
Remove parents from diagnostic hashing.
1 parent afafad0 commit 516b8e6

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

compiler/rustc_error_messages/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,17 @@ impl MultiSpan {
513513
pub fn clone_ignoring_labels(&self) -> Self {
514514
Self { primary_spans: self.primary_spans.clone(), ..MultiSpan::new() }
515515
}
516+
517+
pub fn clone_ignoring_parents(&self) -> Self {
518+
Self {
519+
primary_spans: self.primary_spans.iter().map(|s| s.with_parent(None)).collect(),
520+
span_labels: self
521+
.span_labels
522+
.iter()
523+
.map(|(s, l)| (s.with_parent(None), l.clone()))
524+
.collect(),
525+
}
526+
}
516527
}
517528

518529
impl From<Span> for MultiSpan {

compiler/rustc_errors/src/diagnostic.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -431,19 +431,23 @@ impl DiagInner {
431431
&Level,
432432
&[(DiagMessage, Style)],
433433
&Option<ErrCode>,
434-
&MultiSpan,
435-
&[Subdiag],
436-
&Result<Vec<CodeSuggestion>, SuggestionsDisabled>,
434+
MultiSpan,
435+
Vec<Subdiag>,
436+
Result<Vec<CodeSuggestion>, SuggestionsDisabled>,
437437
Vec<(&DiagArgName, &DiagArgValue)>,
438438
&Option<IsLint>,
439439
) {
440+
let suggestions = match &self.suggestions {
441+
Ok(sugg) => Ok(sugg.iter().map(CodeSuggestion::clone_ignoring_parents).collect()),
442+
Err(SuggestionsDisabled) => Err(SuggestionsDisabled),
443+
};
440444
(
441445
&self.level,
442446
&self.messages,
443447
&self.code,
444-
&self.span,
445-
&self.children,
446-
&self.suggestions,
448+
self.span.clone_ignoring_parents(),
449+
self.children.iter().map(Subdiag::clone_ignoring_parents).collect(),
450+
suggestions,
447451
self.args.iter().collect(),
448452
// omit self.sort_span
449453
&self.is_lint,
@@ -476,6 +480,13 @@ pub struct Subdiag {
476480
pub span: MultiSpan,
477481
}
478482

483+
impl Subdiag {
484+
fn clone_ignoring_parents(&self) -> Subdiag {
485+
let Subdiag { level, messages, span } = self;
486+
Subdiag { level: *level, messages: messages.clone(), span: span.clone_ignoring_parents() }
487+
}
488+
}
489+
479490
/// Used for emitting structured error messages and other diagnostic information.
480491
/// Wraps a `DiagInner`, adding some useful things.
481492
/// - The `dcx` field, allowing it to (a) emit itself, and (b) do a drop check

compiler/rustc_errors/src/lib.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,29 @@ impl SubstitutionPart {
197197
sm.span_to_snippet(self.span)
198198
.map_or(!self.span.is_empty(), |snippet| !snippet.trim().is_empty())
199199
}
200+
201+
fn clone_ignoring_parents(&self) -> SubstitutionPart {
202+
let SubstitutionPart { span, snippet } = self;
203+
SubstitutionPart { span: span.with_parent(None), snippet: snippet.clone() }
204+
}
200205
}
201206

202207
impl CodeSuggestion {
208+
pub fn clone_ignoring_parents(&self) -> CodeSuggestion {
209+
let CodeSuggestion { substitutions, msg, style, applicability } = self;
210+
CodeSuggestion {
211+
substitutions: substitutions
212+
.iter()
213+
.map(|Substitution { parts }| Substitution {
214+
parts: parts.iter().map(SubstitutionPart::clone_ignoring_parents).collect(),
215+
})
216+
.collect(),
217+
msg: msg.clone(),
218+
style: *style,
219+
applicability: *applicability,
220+
}
221+
}
222+
203223
/// Returns the assembled code suggestions, whether they should be shown with an underline
204224
/// and whether the substitution only differs in capitalization.
205225
pub(crate) fn splice_lines(
@@ -1575,6 +1595,7 @@ impl DiagCtxtInner {
15751595
let mut hasher = StableHasher::new();
15761596
diagnostic.hash(&mut hasher);
15771597
let diagnostic_hash = hasher.finish();
1598+
debug!(?diagnostic, ?diagnostic_hash);
15781599
!self.emitted_diagnostics.insert(diagnostic_hash)
15791600
};
15801601

@@ -1584,18 +1605,14 @@ impl DiagCtxtInner {
15841605
// Only emit the diagnostic if we've been asked to deduplicate or
15851606
// haven't already emitted an equivalent diagnostic.
15861607
if !(self.flags.deduplicate_diagnostics && already_emitted) {
1587-
debug!(?diagnostic);
1588-
debug!(?self.emitted_diagnostics);
1589-
15901608
let already_emitted_sub = |sub: &mut Subdiag| {
1591-
debug!(?sub);
15921609
if sub.level != OnceNote && sub.level != OnceHelp {
15931610
return false;
15941611
}
15951612
let mut hasher = StableHasher::new();
15961613
sub.hash(&mut hasher);
15971614
let diagnostic_hash = hasher.finish();
1598-
debug!(?diagnostic_hash);
1615+
debug!(?sub, ?diagnostic_hash);
15991616
!self.emitted_diagnostics.insert(diagnostic_hash)
16001617
};
16011618
diagnostic.children.extract_if(already_emitted_sub).for_each(|_| {});

0 commit comments

Comments
 (0)