about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNikita Tomashevich <quant3234@gmail.com>2022-10-14 21:50:06 +0300
committerNikita Tomashevich <quant3234@gmail.com>2022-12-28 14:53:47 +0300
commiteb7ce1703bb719c1d038be6572a349a3e70f7ca2 (patch)
tree08b05f4bf37f2453cb2d0e450eb110a74e685b8e
parent71d24da665c122fe885d0f62917c01b7f8e8d77f (diff)
downloadrust-eb7ce1703bb719c1d038be6572a349a3e70f7ca2.tar.gz
rust-eb7ce1703bb719c1d038be6572a349a3e70f7ca2.zip
Use eager translation
-rw-r--r--compiler/rustc_error_messages/locales/en-US/infer.ftl2
-rw-r--r--compiler/rustc_infer/src/errors/mod.rs38
2 files changed, 28 insertions, 12 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/infer.ftl b/compiler/rustc_error_messages/locales/en-US/infer.ftl
index 4a43d150968..4219964a877 100644
--- a/compiler/rustc_error_messages/locales/en-US/infer.ftl
+++ b/compiler/rustc_error_messages/locales/en-US/infer.ftl
@@ -258,7 +258,7 @@ infer_trait_impl_diff = `impl` item signature doesn't match `trait` item signatu
                {"   "}found `{$found}`
 
 infer_tid_rel_help = verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output
-infer_tid_consider_borriwing = consider borrowing this type parameter in the trait
+infer_tid_consider_borrowing = consider borrowing this type parameter in the trait
 infer_tid_param_help = the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
 
 infer_dtcs_has_lifetime_req_label = this has an implicit `'static` lifetime requirement
diff --git a/compiler/rustc_infer/src/errors/mod.rs b/compiler/rustc_infer/src/errors/mod.rs
index 69fc3be2bc3..9092874dfae 100644
--- a/compiler/rustc_infer/src/errors/mod.rs
+++ b/compiler/rustc_infer/src/errors/mod.rs
@@ -544,7 +544,6 @@ pub struct ExplicitLifetimeRequired<'a> {
 
 #[derive(Subdiagnostic)]
 pub enum ActualImplExplNotes {
-    // Field names have to be different across Expected* and ButActually variants
     #[note(infer::actual_impl_expl_expected_signature_two)]
     ExpectedSignatureTwo {
         leading_ellipsis: bool,
@@ -731,7 +730,7 @@ pub struct TraitPlaceholderMismatch {
     pub def_id: String,
     pub trait_def_id: String,
 
-    #[subdiagnostic]
+    #[subdiagnostic(eager)]
     pub actual_impl_expl_notes: Vec<ActualImplExplNotes>,
 }
 
@@ -740,12 +739,17 @@ pub struct ConsiderBorrowingParamHelp {
 }
 
 impl AddToDiagnostic for ConsiderBorrowingParamHelp {
-    fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
+    fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, f: F)
+    where
+        F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
+    {
         let mut type_param_span: MultiSpan = self.spans.clone().into();
         for &span in &self.spans {
-            type_param_span.push_span_label(span, fluent::infer::tid_consider_borriwing);
+            // Seems like we can't call f() here as Into<DiagnosticMessage> is required
+            type_param_span.push_span_label(span, fluent::infer::tid_consider_borrowing);
         }
-        diag.span_help(type_param_span, fluent::infer::tid_param_help);
+        let msg = f(diag, fluent::infer::tid_param_help.into());
+        diag.span_help(type_param_span, msg);
     }
 }
 
@@ -779,14 +783,19 @@ pub struct DynTraitConstraintSuggestion {
 }
 
 impl AddToDiagnostic for DynTraitConstraintSuggestion {
-    fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
+    fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, f: F)
+    where
+        F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
+    {
         let mut multi_span: MultiSpan = vec![self.span].into();
         multi_span.push_span_label(self.span, fluent::infer::dtcs_has_lifetime_req_label);
         multi_span.push_span_label(self.ident.span, fluent::infer::dtcs_introduces_requirement);
-        diag.span_note(multi_span, fluent::infer::dtcs_has_req_note);
+        let msg = f(diag, fluent::infer::dtcs_has_req_note.into());
+        diag.span_note(multi_span, msg);
+        let msg = f(diag, fluent::infer::dtcs_suggestion.into());
         diag.span_suggestion_verbose(
             self.span.shrink_to_hi(),
-            fluent::infer::dtcs_suggestion,
+            msg,
             " + '_",
             Applicability::MaybeIncorrect,
         );
@@ -820,7 +829,10 @@ pub struct ReqIntroducedLocations {
 }
 
 impl AddToDiagnostic for ReqIntroducedLocations {
-    fn add_to_diagnostic(mut self, diag: &mut rustc_errors::Diagnostic) {
+    fn add_to_diagnostic_with<F>(mut self, diag: &mut Diagnostic, f: F)
+    where
+        F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
+    {
         for sp in self.spans {
             self.span.push_span_label(sp, fluent::infer::ril_introduced_here);
         }
@@ -829,7 +841,8 @@ impl AddToDiagnostic for ReqIntroducedLocations {
             self.span.push_span_label(self.fn_decl_span, fluent::infer::ril_introduced_by);
         }
         self.span.push_span_label(self.cause_span, fluent::infer::ril_because_of);
-        diag.span_note(self.span, fluent::infer::ril_static_introduced_by);
+        let msg = f(diag, fluent::infer::ril_static_introduced_by.into());
+        diag.span_note(self.span, msg);
     }
 }
 
@@ -838,7 +851,10 @@ pub struct MoreTargeted {
 }
 
 impl AddToDiagnostic for MoreTargeted {
-    fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
+    fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _f: F)
+    where
+        F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
+    {
         diag.code(rustc_errors::error_code!(E0772));
         diag.set_primary_message(fluent::infer::more_targeted);
         diag.set_arg("ident", self.ident);