Skip to content

Commit 969869b

Browse files
committed
Remove parents from diagnostic hashing.
1 parent 0fb279b commit 969869b

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

compiler/rustc_error_messages/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,17 @@ impl MultiSpan {
498498
pub fn clone_ignoring_labels(&self) -> Self {
499499
Self { primary_spans: self.primary_spans.clone(), ..MultiSpan::new() }
500500
}
501+
502+
pub fn clone_ignoring_parents(&self) -> Self {
503+
Self {
504+
primary_spans: self.primary_spans.iter().map(|s| s.with_parent(None)).collect(),
505+
span_labels: self
506+
.span_labels
507+
.iter()
508+
.map(|(s, l)| (s.with_parent(None), l.clone()))
509+
.collect(),
510+
}
511+
}
501512
}
502513

503514
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
@@ -433,19 +433,28 @@ impl DiagInner {
433433
&Level,
434434
&[(DiagMessage, Style)],
435435
&Option<ErrCode>,
436-
&MultiSpan,
437-
&[Subdiag],
438-
&Suggestions,
436+
MultiSpan,
437+
Vec<Subdiag>,
438+
Suggestions,
439439
Vec<(&DiagArgName, &DiagArgValue)>,
440440
&Option<IsLint>,
441441
) {
442+
let suggestions = match &self.suggestions {
443+
Suggestions::Enabled(sugg) => Suggestions::Enabled(
444+
sugg.iter().map(CodeSuggestion::clone_ignoring_parents).collect(),
445+
),
446+
Suggestions::Sealed(sugg) => Suggestions::Sealed(
447+
sugg.iter().map(CodeSuggestion::clone_ignoring_parents).collect(),
448+
),
449+
Suggestions::Disabled => Suggestions::Disabled,
450+
};
442451
(
443452
&self.level,
444453
&self.messages,
445454
&self.code,
446-
&self.span,
447-
&self.children,
448-
&self.suggestions,
455+
self.span.clone_ignoring_parents(),
456+
self.children.iter().map(Subdiag::clone_ignoring_parents).collect(),
457+
suggestions,
449458
self.args.iter().collect(),
450459
// omit self.sort_span
451460
&self.is_lint,
@@ -478,6 +487,13 @@ pub struct Subdiag {
478487
pub span: MultiSpan,
479488
}
480489

490+
impl Subdiag {
491+
fn clone_ignoring_parents(&self) -> Subdiag {
492+
let Subdiag { level, messages, span } = self;
493+
Subdiag { level: *level, messages: messages.clone(), span: span.clone_ignoring_parents() }
494+
}
495+
}
496+
481497
/// Used for emitting structured error messages and other diagnostic information.
482498
/// Wraps a `DiagInner`, adding some useful things.
483499
/// - The `dcx` field, allowing it to (a) emit itself, and (b) do a drop check

compiler/rustc_errors/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ impl SubstitutionPart {
259259
.map_or(!self.span.is_empty(), |snippet| !snippet.trim().is_empty())
260260
}
261261

262+
fn clone_ignoring_parents(&self) -> SubstitutionPart {
263+
let SubstitutionPart { span, snippet } = self;
264+
SubstitutionPart { span: span.with_parent(None), snippet: snippet.clone() }
265+
}
266+
262267
/// Try to turn a replacement into an addition when the span that is being
263268
/// overwritten matches either the prefix or suffix of the replacement.
264269
fn trim_trivial_replacements(&mut self, sm: &SourceMap) {
@@ -303,6 +308,21 @@ fn as_substr<'a>(original: &'a str, suggestion: &'a str) -> Option<(usize, &'a s
303308
}
304309

305310
impl CodeSuggestion {
311+
pub fn clone_ignoring_parents(&self) -> CodeSuggestion {
312+
let CodeSuggestion { substitutions, msg, style, applicability } = self;
313+
CodeSuggestion {
314+
substitutions: substitutions
315+
.iter()
316+
.map(|Substitution { parts }| Substitution {
317+
parts: parts.iter().map(SubstitutionPart::clone_ignoring_parents).collect(),
318+
})
319+
.collect(),
320+
msg: msg.clone(),
321+
style: *style,
322+
applicability: *applicability,
323+
}
324+
}
325+
306326
/// Returns the assembled code suggestions, whether they should be shown with an underline
307327
/// and whether the substitution only differs in capitalization.
308328
pub(crate) fn splice_lines(
@@ -1612,6 +1632,7 @@ impl DiagCtxtInner {
16121632
let mut hasher = StableHasher::new();
16131633
diagnostic.hash(&mut hasher);
16141634
let diagnostic_hash = hasher.finish();
1635+
debug!(?diagnostic, ?diagnostic_hash);
16151636
!self.emitted_diagnostics.insert(diagnostic_hash)
16161637
};
16171638

0 commit comments

Comments
 (0)