diff --git a/compiler/rustc_error_messages/locales/en-US/infer.ftl b/compiler/rustc_error_messages/locales/en-US/infer.ftl index 4a43d150968f..4219964a8773 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 69fc3be2bc3a..9092874dfae7 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, } @@ -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(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 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(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(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(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);