mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #153414 - JonathanBrouwer:translate_cleanup, r=Kivooeo
Rename translation -> formatting Because there is no translation happening anymore r? @Kivooeo
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
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,
|
||||
|
||||
@@ -1135,7 +1135,7 @@ pub fn tool_only_span_suggestion(
|
||||
} }
|
||||
|
||||
/// 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 {
|
||||
@@ -1145,12 +1145,12 @@ pub fn subdiagnostic(&mut self, subdiagnostic: impl Subdiagnostic) -> &mut Self
|
||||
|
||||
/// 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,
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
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,
|
||||
};
|
||||
|
||||
@@ -8,10 +8,7 @@
|
||||
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)
|
||||
@@ -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 =
|
||||
@@ -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:?}");
|
||||
}
|
||||
@@ -30,8 +30,8 @@
|
||||
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)]
|
||||
@@ -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),
|
||||
@@ -330,7 +330,7 @@ fn flush(&mut self) -> io::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -380,7 +380,7 @@ fn flush(&mut self) -> io::Result<()> {
|
||||
let buf = String::from_utf8(buf).unwrap();
|
||||
|
||||
Diagnostic {
|
||||
message: translated_message.to_string(),
|
||||
message: formatted_message.to_string(),
|
||||
code,
|
||||
level,
|
||||
spans,
|
||||
@@ -390,9 +390,9 @@ fn flush(&mut self) -> io::Result<()> {
|
||||
}
|
||||
|
||||
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),
|
||||
|
||||
@@ -66,8 +66,8 @@
|
||||
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;
|
||||
@@ -75,11 +75,11 @@
|
||||
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>>;
|
||||
|
||||
@@ -482,24 +482,24 @@ pub fn set_emitter(&self, emitter: Box<dyn Emitter + DynSend>) {
|
||||
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;
|
||||
@@ -1417,17 +1417,17 @@ fn has_errors_or_delayed_bugs(&self) -> Option<ErrorGuaranteed> {
|
||||
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>>,
|
||||
@@ -1436,12 +1436,12 @@ fn eagerly_translate_to_string<'a>(
|
||||
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) {
|
||||
@@ -1507,7 +1507,7 @@ fn flush_delayed(&mut self) {
|
||||
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;
|
||||
@@ -1558,7 +1558,7 @@ fn decorate(self, dcx: &DiagCtxtInner) -> DiagInner {
|
||||
};
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user