Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
{
let mut span: MultiSpan = spans.clone().into();
err.arg("ty", param_ty.to_string());
let msg = err.dcx.eagerly_translate_to_string(
let msg = err.dcx.eagerly_format_to_string(
msg!("`{$ty}` is made to be an `FnOnce` closure here"),
err.args.iter(),
);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_builtin_macros/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ pub(crate) struct FormatUnusedArg {
impl Subdiagnostic for FormatUnusedArg {
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
diag.arg("named", self.named);
let msg = diag.eagerly_translate(msg!(
let msg = diag.eagerly_format(msg!(
"{$named ->
[true] named argument
*[false] argument
Expand Down Expand Up @@ -947,8 +947,8 @@ pub(crate) struct AsmClobberNoReg {
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AsmClobberNoReg {
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
// eager translation as `span_labels` takes `AsRef<str>`
let lbl1 = dcx.eagerly_translate_to_string(msg!("clobber_abi"), [].into_iter());
let lbl2 = dcx.eagerly_translate_to_string(msg!("generic outputs"), [].into_iter());
let lbl1 = dcx.eagerly_format_to_string(msg!("clobber_abi"), [].into_iter());
let lbl2 = dcx.eagerly_format_to_string(msg!("generic outputs"), [].into_iter());
Diag::new(
dcx,
level,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for ParseTargetMachineConfig<'_> {
fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
let diag: Diag<'_, G> = self.0.into_diag(dcx, level);
let (message, _) = diag.messages.first().expect("`LlvmError` with no message");
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args.iter());
let message = dcx.eagerly_format_to_string(message.clone(), diag.args.iter());
Diag::new(
dcx,
level,
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl Subdiagnostic for FrameNote {
if self.has_label && !self.span.is_dummy() {
span.push_span_label(self.span, msg!("the failure occurred here"));
}
let msg = diag.eagerly_translate(msg!(
let msg = diag.eagerly_format(msg!(
r#"{$times ->
[0] inside {$where_ ->
[closure] closure
Expand Down Expand Up @@ -624,7 +624,7 @@ pub trait ReportErrorExt {
let mut diag = dcx.struct_allow(DiagMessage::Str(String::new().into()));
let message = self.diagnostic_message();
self.add_args(&mut diag);
let s = dcx.eagerly_translate_to_string(message, diag.args.iter());
let s = dcx.eagerly_format_to_string(message, diag.args.iter());
diag.cancel();
s
})
Expand Down Expand Up @@ -1086,12 +1086,12 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
}

let message = if let Some(path) = self.path {
err.dcx.eagerly_translate_to_string(
err.dcx.eagerly_format_to_string(
msg!("constructing invalid value at {$path}"),
[("path".into(), DiagArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)),
)
} else {
err.dcx.eagerly_translate_to_string(msg!("constructing invalid value"), [].into_iter())
err.dcx.eagerly_format_to_string(msg!("constructing invalid value"), [].into_iter())
};

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

Expand All @@ -1144,7 +1144,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
ExpectedKind::EnumTag => msg!("expected a valid enum tag"),
ExpectedKind::Str => msg!("expected a string"),
};
let msg = err.dcx.eagerly_translate_to_string(msg, [].into_iter());
let msg = err.dcx.eagerly_format_to_string(msg, [].into_iter());
err.arg("expected", msg);
}
InvalidEnumTag { value }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ pub fn format_interp_error<'tcx>(dcx: DiagCtxtHandle<'_>, e: InterpErrorInfo<'tc
let mut diag = dcx.struct_allow("");
let msg = e.diagnostic_message();
e.add_args(&mut diag);
let s = dcx.eagerly_translate_to_string(msg, diag.args.iter());
let s = dcx.eagerly_format_to_string(msg, diag.args.iter());
diag.cancel();
s
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::emitter::{
ConfusionType, Destination, MAX_SUGGESTIONS, OutputTheme, detect_confusion_type, is_different,
normalize_whitespace, should_show_source_code,
};
use crate::translation::{format_diag_message, format_diag_messages};
use crate::formatting::{format_diag_message, format_diag_messages};
use crate::{
CodeSuggestion, DiagInner, DiagMessage, Emitter, ErrCode, Level, MultiSpan, Style, Subdiag,
SuggestionStyle, TerminalUrl,
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
} }

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

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

with_fn! { with_span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use rustc_span::source_map::SourceMap;
use rustc_span::{FileName, SourceFile, Span};
use tracing::{debug, warn};

use crate::formatting::format_diag_message;
use crate::timings::TimingRecord;
use crate::translation::format_diag_message;
use crate::{
CodeSuggestion, DiagInner, DiagMessage, Level, MultiSpan, Style, Subdiag, SuggestionStyle,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use crate::fluent_bundle::FluentResource;
use crate::{DiagArg, DiagMessage, Style, fluent_bundle};

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

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

let mut errs = vec![];
let translated = bundle.format_pattern(value, Some(&args), &mut errs).to_string();
debug!(?translated, ?errs);
let formatted = bundle.format_pattern(value, Some(&args), &mut errs).to_string();
debug!(?formatted, ?errs);
if errs.is_empty() {
Cow::Owned(translated)
Cow::Owned(formatted)
} else {
panic!("Fluent errors while formatting message: {errs:?}");
}
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use crate::emitter::{
ColorConfig, Destination, Emitter, HumanReadableErrorType, OutputTheme, TimingEvent,
should_show_source_code,
};
use crate::formatting::{format_diag_message, format_diag_messages};
use crate::timings::{TimingRecord, TimingSection};
use crate::translation::{format_diag_message, format_diag_messages};
use crate::{CodeSuggestion, MultiSpan, SpanLabel, Subdiag, Suggestions, TerminalUrl};

#[cfg(test)]
Expand Down Expand Up @@ -299,9 +299,9 @@ impl Diagnostic {
/// Converts from `rustc_errors::DiagInner` to `Diagnostic`.
fn from_errors_diagnostic(diag: crate::DiagInner, je: &JsonEmitter) -> Diagnostic {
let sugg_to_diag = |sugg: &CodeSuggestion| {
let translated_message = format_diag_message(&sugg.msg, &diag.args);
let formatted_message = format_diag_message(&sugg.msg, &diag.args);
Diagnostic {
message: translated_message.to_string(),
message: formatted_message.to_string(),
code: None,
level: "help",
spans: DiagnosticSpan::from_suggestion(sugg, &diag.args, je),
Expand Down Expand Up @@ -330,7 +330,7 @@ impl Diagnostic {
}
}

let translated_message = format_diag_messages(&diag.messages, &diag.args);
let formatted_message = format_diag_messages(&diag.messages, &diag.args);

let code = if let Some(code) = diag.code {
Some(DiagnosticCode {
Expand Down Expand Up @@ -380,7 +380,7 @@ impl Diagnostic {
let buf = String::from_utf8(buf).unwrap();

Diagnostic {
message: translated_message.to_string(),
message: formatted_message.to_string(),
code,
level,
spans,
Expand All @@ -390,9 +390,9 @@ impl Diagnostic {
}

fn from_sub_diagnostic(subdiag: &Subdiag, args: &DiagArgMap, je: &JsonEmitter) -> Diagnostic {
let translated_message = format_diag_messages(&subdiag.messages, args);
let formatted_message = format_diag_messages(&subdiag.messages, args);
Diagnostic {
message: translated_message.to_string(),
message: formatted_message.to_string(),
code: None,
level: subdiag.level.to_str(),
spans: DiagnosticSpan::from_multispan(&subdiag.span, args, je),
Expand Down
34 changes: 17 additions & 17 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ use rustc_span::{DUMMY_SP, Span};
use tracing::debug;

use crate::emitter::TimingEvent;
use crate::formatting::format_diag_message;
use crate::timings::TimingRecord;
use crate::translation::format_diag_message;

pub mod annotate_snippet_emitter_writer;
pub mod codes;
mod decorate_diag;
mod diagnostic;
mod diagnostic_impls;
pub mod emitter;
pub mod formatting;
pub mod json;
mod lock;
pub mod markdown;
pub mod timings;
pub mod translation;

pub type PResult<'a, T> = Result<T, Diag<'a>>;

Expand Down Expand Up @@ -484,24 +484,24 @@ impl DiagCtxt {
self.inner.borrow_mut().emitter = emitter;
}

/// Translate `message` eagerly with `args` to `DiagMessage::Eager`.
pub fn eagerly_translate<'a>(
/// Format `message` eagerly with `args` to `DiagMessage::Eager`.
pub fn eagerly_format<'a>(
&self,
message: DiagMessage,
args: impl Iterator<Item = DiagArg<'a>>,
) -> DiagMessage {
let inner = self.inner.borrow();
inner.eagerly_translate(message, args)
inner.eagerly_format(message, args)
}

/// Translate `message` eagerly with `args` to `String`.
pub fn eagerly_translate_to_string<'a>(
/// Format `message` eagerly with `args` to `String`.
pub fn eagerly_format_to_string<'a>(
&self,
message: DiagMessage,
args: impl Iterator<Item = DiagArg<'a>>,
) -> String {
let inner = self.inner.borrow();
inner.eagerly_translate_to_string(message, args)
inner.eagerly_format_to_string(message, args)
}

// This is here to not allow mutation of flags;
Expand Down Expand Up @@ -1419,17 +1419,17 @@ impl DiagCtxtInner {
self.has_errors().or_else(|| self.delayed_bugs.get(0).map(|(_, guar)| guar).copied())
}

/// Translate `message` eagerly with `args` to `DiagMessage::Eager`.
fn eagerly_translate<'a>(
/// Format `message` eagerly with `args` to `DiagMessage::Eager`.
fn eagerly_format<'a>(
&self,
message: DiagMessage,
args: impl Iterator<Item = DiagArg<'a>>,
) -> DiagMessage {
DiagMessage::Str(Cow::from(self.eagerly_translate_to_string(message, args)))
DiagMessage::Str(Cow::from(self.eagerly_format_to_string(message, args)))
}

/// Translate `message` eagerly with `args` to `String`.
fn eagerly_translate_to_string<'a>(
/// Format `message` eagerly with `args` to `String`.
fn eagerly_format_to_string<'a>(
&self,
message: DiagMessage,
args: impl Iterator<Item = DiagArg<'a>>,
Expand All @@ -1438,12 +1438,12 @@ impl DiagCtxtInner {
format_diag_message(&message, &args).to_string()
}

fn eagerly_translate_for_subdiag(
fn eagerly_format_for_subdiag(
&self,
diag: &DiagInner,
msg: impl Into<DiagMessage>,
) -> DiagMessage {
self.eagerly_translate(msg.into(), diag.args.iter())
self.eagerly_format(msg.into(), diag.args.iter())
}

fn flush_delayed(&mut self) {
Expand Down Expand Up @@ -1509,7 +1509,7 @@ impl DiagCtxtInner {
let msg = msg!(
"`flushed_delayed` got diagnostic with level {$level}, instead of the expected `DelayedBug`"
);
let msg = self.eagerly_translate_for_subdiag(&bug, msg); // after the `arg` call
let msg = self.eagerly_format_for_subdiag(&bug, msg); // after the `arg` call
bug.sub(Note, msg, bug.span.primary_span().unwrap().into());
}
bug.level = Bug;
Expand Down Expand Up @@ -1560,7 +1560,7 @@ impl DelayedDiagInner {
};
diag.arg("emitted_at", diag.emitted_at.clone());
diag.arg("note", self.note);
let msg = dcx.eagerly_translate_for_subdiag(&diag, msg); // after the `arg` calls
let msg = dcx.eagerly_format_for_subdiag(&diag, msg); // after the `arg` calls
diag.sub(Note, msg, diag.span.primary_span().unwrap_or(DUMMY_SP).into());
diag
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,13 +987,13 @@ impl rustc_errors::Subdiagnostic for CastUnknownPointerSub {
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
match self {
CastUnknownPointerSub::To(span) => {
let msg = diag.eagerly_translate(msg!("needs more type information"));
let msg = diag.eagerly_format(msg!("needs more type information"));
diag.span_label(span, msg);
let msg = diag.eagerly_translate(msg!("the type information given here is insufficient to check whether the pointer cast is valid"));
let msg = diag.eagerly_format(msg!("the type information given here is insufficient to check whether the pointer cast is valid"));
diag.note(msg);
}
CastUnknownPointerSub::From(span) => {
let msg = diag.eagerly_translate(msg!("the type information given here is insufficient to check whether the pointer cast is valid"));
let msg = diag.eagerly_format(msg!("the type information given here is insufficient to check whether the pointer cast is valid"));
diag.span_label(span, msg);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/if_let_rescope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl Subdiagnostic for IfLetRescopeRewrite {
.chain(repeat_n('}', closing_brackets.count))
.collect(),
));
let msg = diag.eagerly_translate(msg!(
let msg = diag.eagerly_format(msg!(
"a `match` with a single arm can preserve the drop order up to Edition 2021"
));
diag.multipart_suggestion_with_style(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3629,7 +3629,7 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {

Explicit { lifetime_name, suggestions, optional_alternative } => {
diag.arg("lifetime_name", lifetime_name);
let msg = diag.eagerly_translate(msg!("consistently use `{$lifetime_name}`"));
let msg = diag.eagerly_format(msg!("consistently use `{$lifetime_name}`"));
diag.remove_arg("lifetime_name");
diag.multipart_suggestion_with_style(
msg,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/diagnostics/subdiagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
for (kind, messages) in kind_messages {
let message = format_ident!("__message");
let message_stream = messages.diag_message(Some(self.variant));
calls.extend(quote! { let #message = #diag.eagerly_translate(#message_stream); });
calls.extend(quote! { let #message = #diag.eagerly_format(#message_stream); });

let name = format_ident!("{}{}", if span_field.is_some() { "span_" } else { "" }, kind);
let call = match kind {
Expand Down
Loading
Loading