about summary refs log tree commit diff
path: root/compiler/rustc_errors/src/diagnostic.rs
diff options
context:
space:
mode:
authorDavid Wood <david.wood@huawei.com>2024-02-14 14:17:27 +0000
committerDavid Wood <david.wood@huawei.com>2024-02-15 10:34:41 +0000
commitb80fc5d4e8ce95a00b14a50e8ee0561b64736480 (patch)
tree45abb838c92b744c86534d7174533a2438e61fe8 /compiler/rustc_errors/src/diagnostic.rs
parentbb89df6903539e7014b8db29bccd6a9ee9553122 (diff)
downloadrust-b80fc5d4e8ce95a00b14a50e8ee0561b64736480.tar.gz
rust-b80fc5d4e8ce95a00b14a50e8ee0561b64736480.zip
errors: only eagerly translate subdiagnostics
Subdiagnostics don't need to be lazily translated, they can always be
eagerly translated. Eager translation is slightly more complex as we need
to have a `DiagCtxt` available to perform the translation, which involves
slightly more threading of that context.

This slight increase in complexity should enable later simplifications -
like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages
into the diagnostic structs rather than having them in separate files
(working on that was what led to this change).

Signed-off-by: David Wood <david@davidtw.co>
Diffstat (limited to 'compiler/rustc_errors/src/diagnostic.rs')
-rw-r--r--compiler/rustc_errors/src/diagnostic.rs11
1 files changed, 2 insertions, 9 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs
index b14a12175c7..d31321b48d0 100644
--- a/compiler/rustc_errors/src/diagnostic.rs
+++ b/compiler/rustc_errors/src/diagnostic.rs
@@ -852,17 +852,10 @@ impl Diagnostic {
     }
 
     /// Add a subdiagnostic from a type that implements `Subdiagnostic` (see
-    /// [rustc_macros::Subdiagnostic]).
-    pub fn subdiagnostic(&mut self, subdiagnostic: impl AddToDiagnostic) -> &mut Self {
-        subdiagnostic.add_to_diagnostic(self);
-        self
-    }
-
-    /// Add a subdiagnostic from a type that implements `Subdiagnostic` (see
     /// [rustc_macros::Subdiagnostic]). Performs eager translation of any translatable messages
     /// used in the subdiagnostic, so suitable for use with repeated messages (i.e. re-use of
     /// interpolated variables).
-    pub fn eager_subdiagnostic(
+    pub fn subdiagnostic(
         &mut self,
         dcx: &crate::DiagCtxt,
         subdiagnostic: impl AddToDiagnostic,
@@ -921,7 +914,7 @@ impl Diagnostic {
     /// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagnosticMessage` by
     /// combining it with the primary message of the diagnostic (if translatable, otherwise it just
     /// passes the user's string along).
-    fn subdiagnostic_message_to_diagnostic_message(
+    pub(crate) fn subdiagnostic_message_to_diagnostic_message(
         &self,
         attr: impl Into<SubdiagnosticMessage>,
     ) -> DiagnosticMessage {