Skip to content

Commit d602394

Browse files
committed
Change message type in bug functions.
From `impl Into<DiagnosticMessage>` to `impl Into<Cow<'static, str>>`. Because these functions don't produce user-facing output and we don't want their strings to be translated.
1 parent 1547c07 commit d602394

File tree

5 files changed

+36
-23
lines changed

5 files changed

+36
-23
lines changed

compiler/rustc_abi/src/layout.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
use std::borrow::{Borrow, Cow};
2+
use std::cmp;
13
use std::fmt::{self, Write};
4+
use std::iter;
5+
use std::ops::Bound;
26
use std::ops::Deref;
3-
use std::{borrow::Borrow, cmp, iter, ops::Bound};
47

58
use rustc_index::Idx;
69
use tracing::debug;
@@ -32,7 +35,7 @@ where
3235
pub trait LayoutCalculator {
3336
type TargetDataLayoutRef: Borrow<TargetDataLayout>;
3437

35-
fn delayed_bug(&self, txt: String);
38+
fn delayed_bug(&self, txt: impl Into<Cow<'static, str>>);
3639
fn current_data_layout(&self) -> Self::TargetDataLayoutRef;
3740

3841
fn scalar_pair<FieldIdx: Idx, VariantIdx: Idx>(

compiler/rustc_errors/src/lib.rs

+24-16
Original file line numberDiff line numberDiff line change
@@ -1076,32 +1076,36 @@ impl DiagCtxt {
10761076
// Functions beginning with `struct_`/`create_` create a diagnostic. Other
10771077
// functions create and emit a diagnostic all in one go.
10781078
impl DiagCtxt {
1079-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1079+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagMessage>` because bug messages aren't
1080+
// user-facing.
10801081
#[track_caller]
1081-
pub fn struct_bug(&self, msg: impl Into<DiagMessage>) -> Diag<'_, BugAbort> {
1082-
Diag::new(self, Bug, msg)
1082+
pub fn struct_bug(&self, msg: impl Into<Cow<'static, str>>) -> Diag<'_, BugAbort> {
1083+
Diag::new(self, Bug, msg.into())
10831084
}
10841085

1085-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1086+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagMessage>` because bug messages aren't
1087+
// user-facing.
10861088
#[track_caller]
1087-
pub fn bug(&self, msg: impl Into<DiagMessage>) -> ! {
1089+
pub fn bug(&self, msg: impl Into<Cow<'static, str>>) -> ! {
10881090
self.struct_bug(msg).emit()
10891091
}
10901092

1091-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1093+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagMessage>` because bug messages aren't
1094+
// user-facing.
10921095
#[track_caller]
10931096
pub fn struct_span_bug(
10941097
&self,
10951098
span: impl Into<MultiSpan>,
1096-
msg: impl Into<DiagMessage>,
1099+
msg: impl Into<Cow<'static, str>>,
10971100
) -> Diag<'_, BugAbort> {
10981101
self.struct_bug(msg).with_span(span)
10991102
}
11001103

1101-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1104+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagMessage>` because bug messages aren't
1105+
// user-facing.
11021106
#[track_caller]
1103-
pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>) -> ! {
1104-
self.struct_span_bug(span, msg).emit()
1107+
pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<Cow<'static, str>>) -> ! {
1108+
self.struct_span_bug(span, msg.into()).emit()
11051109
}
11061110

11071111
#[track_caller]
@@ -1215,24 +1219,28 @@ impl DiagCtxt {
12151219
}
12161220

12171221
/// Ensures that an error is printed. See `Level::DelayedBug`.
1218-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1222+
//
1223+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagMessage>` because bug messages aren't
1224+
// user-facing.
12191225
#[track_caller]
1220-
pub fn delayed_bug(&self, msg: impl Into<DiagMessage>) -> ErrorGuaranteed {
1221-
Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg).emit()
1226+
pub fn delayed_bug(&self, msg: impl Into<Cow<'static, str>>) -> ErrorGuaranteed {
1227+
Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg.into()).emit()
12221228
}
12231229

12241230
/// Ensures that an error is printed. See `Level::DelayedBug`.
12251231
///
12261232
/// Note: this function used to be called `delay_span_bug`. It was renamed
12271233
/// to match similar functions like `span_err`, `span_warn`, etc.
1228-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1234+
//
1235+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagMessage>` because bug messages aren't
1236+
// user-facing.
12291237
#[track_caller]
12301238
pub fn span_delayed_bug(
12311239
&self,
12321240
sp: impl Into<MultiSpan>,
1233-
msg: impl Into<DiagMessage>,
1241+
msg: impl Into<Cow<'static, str>>,
12341242
) -> ErrorGuaranteed {
1235-
Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg).with_span(sp).emit()
1243+
Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg.into()).with_span(sp).emit()
12361244
}
12371245

12381246
#[rustc_lint_diagnostics]

compiler/rustc_middle/src/ty/layout.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_target::abi::call::FnAbi;
1717
use rustc_target::abi::*;
1818
use rustc_target::spec::{abi::Abi as SpecAbi, HasTargetSpec, PanicStrategy, Target};
1919

20+
use std::borrow::Cow;
2021
use std::cmp;
2122
use std::fmt;
2223
use std::num::NonZero;
@@ -268,7 +269,7 @@ pub struct LayoutCx<'tcx, C> {
268269
impl<'tcx> LayoutCalculator for LayoutCx<'tcx, TyCtxt<'tcx>> {
269270
type TargetDataLayoutRef = &'tcx TargetDataLayout;
270271

271-
fn delayed_bug(&self, txt: String) {
272+
fn delayed_bug(&self, txt: impl Into<Cow<'static, str>>) {
272273
self.tcx.dcx().delayed_bug(txt);
273274
}
274275

compiler/rustc_middle/src/ty/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::ty::{GenericArg, GenericArgs, GenericArgsRef};
1313
use crate::ty::{List, ParamEnv};
1414
use hir::def::DefKind;
1515
use rustc_data_structures::captures::Captures;
16-
use rustc_errors::{DiagArgValue, DiagMessage, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan};
16+
use rustc_errors::{DiagArgValue, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan};
1717
use rustc_hir as hir;
1818
use rustc_hir::def_id::DefId;
1919
use rustc_hir::LangItem;
@@ -1543,7 +1543,7 @@ impl<'tcx> Ty<'tcx> {
15431543
pub fn new_error_with_message<S: Into<MultiSpan>>(
15441544
tcx: TyCtxt<'tcx>,
15451545
span: S,
1546-
msg: impl Into<DiagMessage>,
1546+
msg: impl Into<Cow<'static, str>>,
15471547
) -> Ty<'tcx> {
15481548
let reported = tcx.dcx().span_delayed_bug(span, msg);
15491549
Ty::new(tcx, Error(reported))

src/tools/rust-analyzer/crates/hir-ty/src/layout.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Compute the binary representation of a type
22
3+
use std::borrow::Cow;
34
use std::fmt;
45

56
use base_db::salsa::Cycle;
@@ -114,8 +115,8 @@ struct LayoutCx<'a> {
114115
impl<'a> LayoutCalculator for LayoutCx<'a> {
115116
type TargetDataLayoutRef = &'a TargetDataLayout;
116117

117-
fn delayed_bug(&self, txt: String) {
118-
never!("{}", txt);
118+
fn delayed_bug(&self, txt: impl Into<Cow<'static, str>>) {
119+
never!("{}", txt.into());
119120
}
120121

121122
fn current_data_layout(&self) -> &'a TargetDataLayout {

0 commit comments

Comments
 (0)