about summary refs log tree commit diff
path: root/compiler/rustc_errors/src/emitter.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-17 18:20:41 +0000
committerbors <bors@rust-lang.org>2024-02-17 18:20:41 +0000
commitcabdf3ad257693aa79ffcc4b7dd1fdab41dc209e (patch)
tree0b9165c5f70c60fd421dcf652a9998e5e132034f /compiler/rustc_errors/src/emitter.rs
parent12b5498f3bcaa9f7b7641ed829873da0907b21dc (diff)
parenteafa74ab629df7d02dc73fde7db4027f90b2538a (diff)
downloadrust-cabdf3ad257693aa79ffcc4b7dd1fdab41dc209e.tar.gz
rust-cabdf3ad257693aa79ffcc4b7dd1fdab41dc209e.zip
Auto merge of #121240 - matthiaskrgr:rollup-lfb5i9w, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #120952 (Don't use mem::zeroed in vec::IntoIter)
 - #121085 (errors: only eagerly translate subdiagnostics)
 - #121091 (use build.rustc config and skip-stage0-validation flag)
 - #121149 (Fix typo in VecDeque::handle_capacity_increase() doc comment.)
 - #121193 (Use fulfillment in next trait solver coherence)
 - #121209 (Make `CodegenBackend::join_codegen` infallible.)
 - #121210 (Fix `cfg(target_abi = "sim")` on `i386-apple-ios`)
 - #121228 (create stamp file for clippy)
 - #121231 (remove a couple of redundant clones)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_errors/src/emitter.rs')
-rw-r--r--compiler/rustc_errors/src/emitter.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index afb1b854e72..e09c041c1d0 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -10,6 +10,7 @@
 use rustc_span::source_map::SourceMap;
 use rustc_span::{FileLines, FileName, SourceFile, Span};
 
+use crate::error::TranslateError;
 use crate::snippet::{
     Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString,
 };
@@ -559,6 +560,18 @@ pub struct SilentEmitter {
     pub fatal_note: String,
 }
 
+pub fn silent_translate<'a>(
+    message: &'a DiagnosticMessage,
+) -> Result<Cow<'_, str>, TranslateError<'_>> {
+    match message {
+        DiagnosticMessage::Str(msg) | DiagnosticMessage::Translated(msg) => Ok(Cow::Borrowed(msg)),
+        DiagnosticMessage::FluentIdentifier(identifier, _) => {
+            // Any value works here.
+            Ok(identifier.clone())
+        }
+    }
+}
+
 impl Translate for SilentEmitter {
     fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
         None
@@ -567,6 +580,16 @@ impl Translate for SilentEmitter {
     fn fallback_fluent_bundle(&self) -> &FluentBundle {
         panic!("silent emitter attempted to translate message")
     }
+
+    // Override `translate_message` for the silent emitter because eager translation of
+    // subdiagnostics result in a call to this.
+    fn translate_message<'a>(
+        &'a self,
+        message: &'a DiagnosticMessage,
+        _: &'a FluentArgs<'_>,
+    ) -> Result<Cow<'_, str>, TranslateError<'_>> {
+        silent_translate(message)
+    }
 }
 
 impl Emitter for SilentEmitter {