Skip to content

Commit 3857d9c

Browse files
committed
borrowck/errors: fix i18n error in delayed bug
During borrowck, the `MultiSpan` from a buffered diagnostic is cloned and used to emit a delayed bug indicating a diagnostic was buffered - when the buffered diagnostic is translated, then the cloned `MultiSpan` may contain labels which can only render with the diagnostic's arguments, but the delayed bug being emitted won't have those arguments. Adds a function which clones `MultiSpan` without also cloning the contained labels, and use this function when creating the buffered diagnostic delayed bug. Signed-off-by: David Wood <[email protected]>
1 parent ced592a commit 3857d9c

File tree

2 files changed

+12
-5
lines changed
  • compiler

2 files changed

+12
-5
lines changed

compiler/rustc_borrowck/src/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -2306,11 +2306,10 @@ mod error {
23062306

23072307
pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorGuaranteed>) {
23082308
if let None = self.tainted_by_errors {
2309-
self.tainted_by_errors = Some(
2310-
self.tcx
2311-
.sess
2312-
.delay_span_bug(t.span.clone(), "diagnostic buffered but not emitted"),
2313-
)
2309+
self.tainted_by_errors = Some(self.tcx.sess.delay_span_bug(
2310+
t.span.clone_ignoring_labels(),
2311+
"diagnostic buffered but not emitted",
2312+
))
23142313
}
23152314
t.buffer(&mut self.buffered);
23162315
}

compiler/rustc_error_messages/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,14 @@ impl MultiSpan {
533533
pub fn has_span_labels(&self) -> bool {
534534
self.span_labels.iter().any(|(sp, _)| !sp.is_dummy())
535535
}
536+
537+
/// Clone this `MultiSpan` without keeping any of the span labels - sometimes a `MultiSpan` is
538+
/// to be re-used in another diagnostic, but includes `span_labels` which have translated
539+
/// messages. These translated messages would fail to translate without their diagnostic
540+
/// arguments which are unlikely to be cloned alongside the `Span`.
541+
pub fn clone_ignoring_labels(&self) -> Self {
542+
Self { primary_spans: self.primary_spans.clone(), ..MultiSpan::new() }
543+
}
536544
}
537545

538546
impl From<Span> for MultiSpan {

0 commit comments

Comments
 (0)