diff options
| author | David Wood <david.wood@huawei.com> | 2023-07-24 15:47:03 +0100 |
|---|---|---|
| committer | David Wood <david.wood@huawei.com> | 2023-07-24 15:47:03 +0100 |
| commit | 3857d9c2da1250546ccb87ab7ddcc68904f45dc5 (patch) | |
| tree | 5758f069afb5159a1cbb85060e19aef79960ffc3 | |
| parent | ced592a99bfc6ad2c9aa014350686188963764e9 (diff) | |
| download | rust-3857d9c2da1250546ccb87ab7ddcc68904f45dc5.tar.gz rust-3857d9c2da1250546ccb87ab7ddcc68904f45dc5.zip | |
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 <david@davidtw.co>
| -rw-r--r-- | compiler/rustc_borrowck/src/lib.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_error_messages/src/lib.rs | 8 |
2 files changed, 12 insertions, 5 deletions
diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index ea32506fc89..2fd42e2f56a 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -2306,11 +2306,10 @@ mod error { pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorGuaranteed>) { if let None = self.tainted_by_errors { - self.tainted_by_errors = Some( - self.tcx - .sess - .delay_span_bug(t.span.clone(), "diagnostic buffered but not emitted"), - ) + self.tainted_by_errors = Some(self.tcx.sess.delay_span_bug( + t.span.clone_ignoring_labels(), + "diagnostic buffered but not emitted", + )) } t.buffer(&mut self.buffered); } diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 1879ece59e3..a49b842d9ff 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -533,6 +533,14 @@ impl MultiSpan { pub fn has_span_labels(&self) -> bool { self.span_labels.iter().any(|(sp, _)| !sp.is_dummy()) } + + /// Clone this `MultiSpan` without keeping any of the span labels - sometimes a `MultiSpan` is + /// to be re-used in another diagnostic, but includes `span_labels` which have translated + /// messages. These translated messages would fail to translate without their diagnostic + /// arguments which are unlikely to be cloned alongside the `Span`. + pub fn clone_ignoring_labels(&self) -> Self { + Self { primary_spans: self.primary_spans.clone(), ..MultiSpan::new() } + } } impl From<Span> for MultiSpan { |
