Skip to content

Commit 9cc0819

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 bf9c7a6 commit 9cc0819

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

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

1013-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1015+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagnosticMessage>` because bug messages
1016+
// aren't user-facing.
10141017
#[track_caller]
10151018
pub fn struct_span_bug(
10161019
&self,
10171020
span: impl Into<MultiSpan>,
1018-
msg: impl Into<DiagnosticMessage>,
1021+
msg: impl Into<Cow<'static, str>>,
10191022
) -> DiagnosticBuilder<'_, BugAbort> {
10201023
self.struct_bug(msg).with_span(span)
10211024
}
10221025

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

10291033
#[track_caller]
@@ -1143,24 +1147,28 @@ impl DiagCtxt {
11431147
}
11441148

11451149
/// Ensures that an error is printed. See `Level::DelayedBug`.
1146-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1150+
//
1151+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagnosticMessage>` because bug messages
1152+
// aren't user-facing.
11471153
#[track_caller]
1148-
pub fn delayed_bug(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
1149-
DiagnosticBuilder::<ErrorGuaranteed>::new(self, DelayedBug, msg).emit()
1154+
pub fn delayed_bug(&self, msg: impl Into<Cow<'static, str>>) -> ErrorGuaranteed {
1155+
DiagnosticBuilder::<ErrorGuaranteed>::new(self, DelayedBug, msg.into()).emit()
11501156
}
11511157

11521158
/// Ensures that an error is printed. See `Level::DelayedBug`.
11531159
///
11541160
/// Note: this function used to be called `delay_span_bug`. It was renamed
11551161
/// to match similar functions like `span_err`, `span_warn`, etc.
1156-
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1162+
//
1163+
// No `#[rustc_lint_diagnostics]` and no `impl Into<DiagnosticMessage>` because bug messages
1164+
// aren't user-facing.
11571165
#[track_caller]
11581166
pub fn span_delayed_bug(
11591167
&self,
11601168
sp: impl Into<MultiSpan>,
1161-
msg: impl Into<DiagnosticMessage>,
1169+
msg: impl Into<Cow<'static, str>>,
11621170
) -> ErrorGuaranteed {
1163-
DiagnosticBuilder::<ErrorGuaranteed>::new(self, DelayedBug, msg).with_span(sp).emit()
1171+
DiagnosticBuilder::<ErrorGuaranteed>::new(self, DelayedBug, msg.into()).with_span(sp).emit()
11641172
}
11651173

11661174
#[rustc_lint_diagnostics]

compiler/rustc_middle/src/ty/layout.rs

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

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

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

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-
DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan,
18-
};
16+
use rustc_errors::{DiagnosticArgValue, 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)