Skip to content

Commit 53ef4d2

Browse files
Rollup merge of #153414 - JonathanBrouwer:translate_cleanup, r=Kivooeo
Rename translation -> formatting Because there is no translation happening anymore r? @Kivooeo
2 parents 12b6699 + d809214 commit 53ef4d2

21 files changed

Lines changed: 68 additions & 76 deletions

File tree

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13101310
{
13111311
let mut span: MultiSpan = spans.clone().into();
13121312
err.arg("ty", param_ty.to_string());
1313-
let msg = err.dcx.eagerly_translate_to_string(
1313+
let msg = err.dcx.eagerly_format_to_string(
13141314
msg!("`{$ty}` is made to be an `FnOnce` closure here"),
13151315
err.args.iter(),
13161316
);

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ pub(crate) struct FormatUnusedArg {
764764
impl Subdiagnostic for FormatUnusedArg {
765765
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
766766
diag.arg("named", self.named);
767-
let msg = diag.eagerly_translate(msg!(
767+
let msg = diag.eagerly_format(msg!(
768768
"{$named ->
769769
[true] named argument
770770
*[false] argument
@@ -947,8 +947,8 @@ pub(crate) struct AsmClobberNoReg {
947947
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AsmClobberNoReg {
948948
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
949949
// eager translation as `span_labels` takes `AsRef<str>`
950-
let lbl1 = dcx.eagerly_translate_to_string(msg!("clobber_abi"), [].into_iter());
951-
let lbl2 = dcx.eagerly_translate_to_string(msg!("generic outputs"), [].into_iter());
950+
let lbl1 = dcx.eagerly_format_to_string(msg!("clobber_abi"), [].into_iter());
951+
let lbl2 = dcx.eagerly_format_to_string(msg!("generic outputs"), [].into_iter());
952952
Diag::new(
953953
dcx,
954954
level,

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for ParseTargetMachineConfig<'_> {
2424
fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
2525
let diag: Diag<'_, G> = self.0.into_diag(dcx, level);
2626
let (message, _) = diag.messages.first().expect("`LlvmError` with no message");
27-
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args.iter());
27+
let message = dcx.eagerly_format_to_string(message.clone(), diag.args.iter());
2828
Diag::new(
2929
dcx,
3030
level,

compiler/rustc_const_eval/src/errors.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl Subdiagnostic for FrameNote {
366366
if self.has_label && !self.span.is_dummy() {
367367
span.push_span_label(self.span, msg!("the failure occurred here"));
368368
}
369-
let msg = diag.eagerly_translate(msg!(
369+
let msg = diag.eagerly_format(msg!(
370370
r#"{$times ->
371371
[0] inside {$where_ ->
372372
[closure] closure
@@ -624,7 +624,7 @@ pub trait ReportErrorExt {
624624
let mut diag = dcx.struct_allow(DiagMessage::Str(String::new().into()));
625625
let message = self.diagnostic_message();
626626
self.add_args(&mut diag);
627-
let s = dcx.eagerly_translate_to_string(message, diag.args.iter());
627+
let s = dcx.eagerly_format_to_string(message, diag.args.iter());
628628
diag.cancel();
629629
s
630630
})
@@ -1086,12 +1086,12 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
10861086
}
10871087

10881088
let message = if let Some(path) = self.path {
1089-
err.dcx.eagerly_translate_to_string(
1089+
err.dcx.eagerly_format_to_string(
10901090
msg!("constructing invalid value at {$path}"),
10911091
[("path".into(), DiagArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)),
10921092
)
10931093
} else {
1094-
err.dcx.eagerly_translate_to_string(msg!("constructing invalid value"), [].into_iter())
1094+
err.dcx.eagerly_format_to_string(msg!("constructing invalid value"), [].into_iter())
10951095
};
10961096

10971097
err.arg("front_matter", message);
@@ -1122,7 +1122,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
11221122
("hi".into(), DiagArgValue::Str(hi.to_string().into())),
11231123
];
11241124
let args = args.iter().map(|(a, b)| (a, b));
1125-
let message = err.dcx.eagerly_translate_to_string(msg, args);
1125+
let message = err.dcx.eagerly_format_to_string(msg, args);
11261126
err.arg("in_range", message);
11271127
}
11281128

@@ -1144,7 +1144,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
11441144
ExpectedKind::EnumTag => msg!("expected a valid enum tag"),
11451145
ExpectedKind::Str => msg!("expected a string"),
11461146
};
1147-
let msg = err.dcx.eagerly_translate_to_string(msg, [].into_iter());
1147+
let msg = err.dcx.eagerly_format_to_string(msg, [].into_iter());
11481148
err.arg("expected", msg);
11491149
}
11501150
InvalidEnumTag { value }

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub fn format_interp_error<'tcx>(dcx: DiagCtxtHandle<'_>, e: InterpErrorInfo<'tc
235235
let mut diag = dcx.struct_allow("");
236236
let msg = e.diagnostic_message();
237237
e.add_args(&mut diag);
238-
let s = dcx.eagerly_translate_to_string(msg, diag.args.iter());
238+
let s = dcx.eagerly_format_to_string(msg, diag.args.iter());
239239
diag.cancel();
240240
s
241241
}

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::emitter::{
2626
ConfusionType, Destination, MAX_SUGGESTIONS, OutputTheme, detect_confusion_type, is_different,
2727
normalize_whitespace, should_show_source_code,
2828
};
29-
use crate::translation::{format_diag_message, format_diag_messages};
29+
use crate::formatting::{format_diag_message, format_diag_messages};
3030
use crate::{
3131
CodeSuggestion, DiagInner, DiagMessage, Emitter, ErrCode, Level, MultiSpan, Style, Subdiag,
3232
SuggestionStyle, TerminalUrl,

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11351135
} }
11361136

11371137
/// Add a subdiagnostic from a type that implements `Subdiagnostic` (see
1138-
/// [rustc_macros::Subdiagnostic]). Performs eager translation of any translatable messages
1138+
/// [rustc_macros::Subdiagnostic]). Performs eager formatting of any messages
11391139
/// used in the subdiagnostic, so suitable for use with repeated messages (i.e. re-use of
11401140
/// interpolated variables).
11411141
pub fn subdiagnostic(&mut self, subdiagnostic: impl Subdiagnostic) -> &mut Self {
@@ -1145,12 +1145,12 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11451145

11461146
/// Fluent variables are not namespaced from each other, so when
11471147
/// `Diagnostic`s and `Subdiagnostic`s use the same variable name,
1148-
/// one value will clobber the other. Eagerly translating the
1148+
/// one value will clobber the other. Eagerly formatting the
11491149
/// diagnostic uses the variables defined right then, before the
11501150
/// clobbering occurs.
1151-
pub fn eagerly_translate(&self, msg: impl Into<DiagMessage>) -> DiagMessage {
1151+
pub fn eagerly_format(&self, msg: impl Into<DiagMessage>) -> DiagMessage {
11521152
let args = self.args.iter();
1153-
self.dcx.eagerly_translate(msg.into(), args)
1153+
self.dcx.eagerly_format(msg.into(), args)
11541154
}
11551155

11561156
with_fn! { with_span,

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use rustc_span::source_map::SourceMap;
2323
use rustc_span::{FileName, SourceFile, Span};
2424
use tracing::{debug, warn};
2525

26+
use crate::formatting::format_diag_message;
2627
use crate::timings::TimingRecord;
27-
use crate::translation::format_diag_message;
2828
use crate::{
2929
CodeSuggestion, DiagInner, DiagMessage, Level, MultiSpan, Style, Subdiag, SuggestionStyle,
3030
};
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ use crate::fluent_bundle::FluentResource;
88
use crate::{DiagArg, DiagMessage, Style, fluent_bundle};
99

1010
/// Convert diagnostic arguments (a rustc internal type that exists to implement
11-
/// `Encodable`/`Decodable`) into `FluentArgs` which is necessary to perform translation.
12-
///
13-
/// Typically performed once for each diagnostic at the start of `emit_diagnostic` and then
14-
/// passed around as a reference thereafter.
11+
/// `Encodable`/`Decodable`) into `FluentArgs` which is necessary to perform formatting.
1512
fn to_fluent_args<'iter>(iter: impl Iterator<Item = DiagArg<'iter>>) -> FluentArgs<'static> {
1613
let mut args = if let Some(size) = iter.size_hint().1 {
1714
FluentArgs::with_capacity(size)
@@ -40,9 +37,6 @@ pub fn format_diag_message<'a>(message: &'a DiagMessage, args: &DiagArgMap) -> C
4037

4138
match message {
4239
DiagMessage::Str(msg) => Cow::Borrowed(msg),
43-
// This translates an inline fluent diagnostic message
44-
// It does this by creating a new `FluentBundle` with only one message,
45-
// and then translating using this bundle.
4640
DiagMessage::Inline(msg) => {
4741
const GENERATED_MSG_ID: &str = "generated_msg";
4842
let resource =
@@ -56,10 +50,10 @@ pub fn format_diag_message<'a>(message: &'a DiagMessage, args: &DiagArgMap) -> C
5650
let args = to_fluent_args(args.iter());
5751

5852
let mut errs = vec![];
59-
let translated = bundle.format_pattern(value, Some(&args), &mut errs).to_string();
60-
debug!(?translated, ?errs);
53+
let formatted = bundle.format_pattern(value, Some(&args), &mut errs).to_string();
54+
debug!(?formatted, ?errs);
6155
if errs.is_empty() {
62-
Cow::Owned(translated)
56+
Cow::Owned(formatted)
6357
} else {
6458
panic!("Fluent errors while formatting message: {errs:?}");
6559
}

compiler/rustc_errors/src/json.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use crate::emitter::{
3030
ColorConfig, Destination, Emitter, HumanReadableErrorType, OutputTheme, TimingEvent,
3131
should_show_source_code,
3232
};
33+
use crate::formatting::{format_diag_message, format_diag_messages};
3334
use crate::timings::{TimingRecord, TimingSection};
34-
use crate::translation::{format_diag_message, format_diag_messages};
3535
use crate::{CodeSuggestion, MultiSpan, SpanLabel, Subdiag, Suggestions, TerminalUrl};
3636

3737
#[cfg(test)]
@@ -299,9 +299,9 @@ impl Diagnostic {
299299
/// Converts from `rustc_errors::DiagInner` to `Diagnostic`.
300300
fn from_errors_diagnostic(diag: crate::DiagInner, je: &JsonEmitter) -> Diagnostic {
301301
let sugg_to_diag = |sugg: &CodeSuggestion| {
302-
let translated_message = format_diag_message(&sugg.msg, &diag.args);
302+
let formatted_message = format_diag_message(&sugg.msg, &diag.args);
303303
Diagnostic {
304-
message: translated_message.to_string(),
304+
message: formatted_message.to_string(),
305305
code: None,
306306
level: "help",
307307
spans: DiagnosticSpan::from_suggestion(sugg, &diag.args, je),
@@ -330,7 +330,7 @@ impl Diagnostic {
330330
}
331331
}
332332

333-
let translated_message = format_diag_messages(&diag.messages, &diag.args);
333+
let formatted_message = format_diag_messages(&diag.messages, &diag.args);
334334

335335
let code = if let Some(code) = diag.code {
336336
Some(DiagnosticCode {
@@ -380,7 +380,7 @@ impl Diagnostic {
380380
let buf = String::from_utf8(buf).unwrap();
381381

382382
Diagnostic {
383-
message: translated_message.to_string(),
383+
message: formatted_message.to_string(),
384384
code,
385385
level,
386386
spans,
@@ -390,9 +390,9 @@ impl Diagnostic {
390390
}
391391

392392
fn from_sub_diagnostic(subdiag: &Subdiag, args: &DiagArgMap, je: &JsonEmitter) -> Diagnostic {
393-
let translated_message = format_diag_messages(&subdiag.messages, args);
393+
let formatted_message = format_diag_messages(&subdiag.messages, args);
394394
Diagnostic {
395-
message: translated_message.to_string(),
395+
message: formatted_message.to_string(),
396396
code: None,
397397
level: subdiag.level.to_str(),
398398
spans: DiagnosticSpan::from_multispan(&subdiag.span, args, je),

0 commit comments

Comments
 (0)