Skip to content

Commit d6b974d

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 c475e23 commit d6b974d

File tree

5 files changed

+36
-25
lines changed

5 files changed

+36
-25
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
@@ -997,32 +997,36 @@ impl DiagCtxt {
997997
// Functions beginning with `struct_`/`create_` create a diagnostic. Other
998998
// functions create and emit a diagnostic all in one go.
999999
impl DiagCtxt {
1000-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1000+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagnosticMessage>` because bug messages
1001+
// aren't user-facing.
10011002
#[track_caller]
1002-
pub fn struct_bug(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, BugAbort> {
1003-
Diag::new(self, Bug, msg)
1003+
pub fn struct_bug(&self, msg: impl Into<Cow<'static, str>>) -> Diag<'_, BugAbort> {
1004+
Diag::new(self, Bug, msg.into())
10041005
}
10051006

1006-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1007+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagnosticMessage>` because bug messages
1008+
// aren't user-facing.
10071009
#[track_caller]
1008-
pub fn bug(&self, msg: impl Into<DiagnosticMessage>) -> ! {
1010+
pub fn bug(&self, msg: impl Into<Cow<'static, str>>) -> ! {
10091011
self.struct_bug(msg).emit()
10101012
}
10111013

1012-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1014+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagnosticMessage>` because bug messages
1015+
// aren't user-facing.
10131016
#[track_caller]
10141017
pub fn struct_span_bug(
10151018
&self,
10161019
span: impl Into<MultiSpan>,
1017-
msg: impl Into<DiagnosticMessage>,
1020+
msg: impl Into<Cow<'static, str>>,
10181021
) -> Diag<'_, BugAbort> {
10191022
self.struct_bug(msg).with_span(span)
10201023
}
10211024

1022-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1025+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagnosticMessage>` because bug messages
1026+
// aren't user-facing.
10231027
#[track_caller]
1024-
pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
1025-
self.struct_span_bug(span, msg).emit()
1028+
pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<Cow<'static, str>>) -> ! {
1029+
self.struct_span_bug(span, msg.into()).emit()
10261030
}
10271031

10281032
#[track_caller]
@@ -1136,24 +1140,28 @@ impl DiagCtxt {
11361140
}
11371141

11381142
/// Ensures that an error is printed. See `Level::DelayedBug`.
1139-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1143+
//
1144+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagnosticMessage>` because bug messages
1145+
// aren't user-facing.
11401146
#[track_caller]
1141-
pub fn delayed_bug(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
1142-
Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg).emit()
1147+
pub fn delayed_bug(&self, msg: impl Into<Cow<'static, str>>) -> ErrorGuaranteed {
1148+
Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg.into()).emit()
11431149
}
11441150

11451151
/// Ensures that an error is printed. See `Level::DelayedBug`.
11461152
///
11471153
/// Note: this function used to be called `delay_span_bug`. It was renamed
11481154
/// to match similar functions like `span_err`, `span_warn`, etc.
1149-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1155+
//
1156+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagnosticMessage>` because bug messages
1157+
// aren't user-facing.
11501158
#[track_caller]
11511159
pub fn span_delayed_bug(
11521160
&self,
11531161
sp: impl Into<MultiSpan>,
1154-
msg: impl Into<DiagnosticMessage>,
1162+
msg: impl Into<Cow<'static, str>>,
11551163
) -> ErrorGuaranteed {
1156-
Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg).with_span(sp).emit()
1164+
Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg.into()).with_span(sp).emit()
11571165
}
11581166

11591167
#[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;
@@ -266,7 +267,7 @@ pub struct LayoutCx<'tcx, C> {
266267
impl<'tcx> LayoutCalculator for LayoutCx<'tcx, TyCtxt<'tcx>> {
267268
type TargetDataLayoutRef = &'tcx TargetDataLayout;
268269

269-
fn delayed_bug(&self, txt: String) {
270+
fn delayed_bug(&self, txt: impl Into<Cow<'static, str>>) {
270271
self.tcx.dcx().delayed_bug(txt);
271272
}
272273

compiler/rustc_middle/src/ty/sty.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +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::{
17-
DiagArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan,
18-
};
16+
use rustc_errors::{DiagArgValue, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan};
1917
use rustc_hir as hir;
2018
use rustc_hir::def_id::DefId;
2119
use rustc_hir::LangItem;
@@ -1544,7 +1542,7 @@ impl<'tcx> Ty<'tcx> {
15441542
pub fn new_error_with_message<S: Into<MultiSpan>>(
15451543
tcx: TyCtxt<'tcx>,
15461544
span: S,
1547-
msg: impl Into<DiagnosticMessage>,
1545+
msg: impl Into<Cow<'static, str>>,
15481546
) -> Ty<'tcx> {
15491547
let reported = tcx.dcx().span_delayed_bug(span, msg);
15501548
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)