diff --git a/compiler/rustc_error_messages/locales/en-US/infer.ftl b/compiler/rustc_error_messages/locales/en-US/infer.ftl index c012973f1dd..c257bf739d1 100644 --- a/compiler/rustc_error_messages/locales/en-US/infer.ftl +++ b/compiler/rustc_error_messages/locales/en-US/infer.ftl @@ -146,8 +146,10 @@ infer_region_explanation = {$pref_kind -> [source_pointer_valid_for] source pointer is only valid for [type_satisfy] type must satisfy [type_outlive] type must outlive - [lf_instantiated_with] lifetime parameter instantiated with - [lf_must_outlive] but lifetime parameter must outlive + [lf_param_instantiated_with] lifetime parameter instantiated with + [lf_param_must_outlive] but lifetime parameter must outlive + [lf_instantiated_with] lifetime instantiated with + [lf_must_outlive] but lifetime must outlive [type_valid_for] the type is valid for [borrow_lasts_for] but the borrow lasts for [pointer_valid_for] the pointer is valid for diff --git a/compiler/rustc_infer/src/errors/note_and_explain.rs b/compiler/rustc_infer/src/errors/note_and_explain.rs index 3516517dcc3..b212a5a09c0 100644 --- a/compiler/rustc_infer/src/errors/note_and_explain.rs +++ b/compiler/rustc_infer/src/errors/note_and_explain.rs @@ -127,6 +127,8 @@ pub enum PrefixKind { SourcePointerValidFor, TypeSatisfy, TypeOutlive, + LfParamInstantiatedWith, + LfParamMustOutlive, LfInstantiatedWith, LfMustOutlive, TypeValidFor, @@ -151,6 +153,8 @@ impl IntoDiagnosticArg for PrefixKind { Self::SourcePointerValidFor => "source_pointer_valid_for", Self::TypeSatisfy => "type_satisfy", Self::TypeOutlive => "type_outlive", + Self::LfParamInstantiatedWith => "lf_param_instantiated_with", + Self::LfParamMustOutlive => "lf_param_must_outlive", Self::LfInstantiatedWith => "lf_instantiated_with", Self::LfMustOutlive => "lf_must_outlive", Self::TypeValidFor => "type_valid_for", diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs index 4c07cc0b6a2..adf240e7ce5 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs @@ -5,8 +5,8 @@ use crate::errors::{ use crate::infer::error_reporting::{note_and_explain_region, TypeErrCtxt}; use crate::infer::{self, SubregionOrigin}; use rustc_errors::{ - fluent, struct_span_err, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, - ErrorGuaranteed, IntoDiagnostic, + fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, + IntoDiagnostic, }; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::traits::ObligationCauseCode; @@ -184,14 +184,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { self.tcx, sup, None, - note_and_explain::PrefixKind::LfInstantiatedWith, + note_and_explain::PrefixKind::LfParamInstantiatedWith, note_and_explain::SuffixKind::Empty, ); let param_must_outlive = note_and_explain::RegionExplanation::new( self.tcx, sub, None, - note_and_explain::PrefixKind::LfMustOutlive, + note_and_explain::PrefixKind::LfParamMustOutlive, note_and_explain::SuffixKind::Empty, ); LfBoundNotSatisfied { @@ -279,25 +279,25 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { err } infer::AscribeUserTypeProvePredicate(span) => { - let mut err = - struct_span_err!(self.tcx.sess, span, E0478, "lifetime bound not satisfied"); - note_and_explain_region( + let instantiated = note_and_explain::RegionExplanation::new( self.tcx, - &mut err, - "lifetime instantiated with ", sup, - "", None, + note_and_explain::PrefixKind::LfInstantiatedWith, + note_and_explain::SuffixKind::Empty, ); - note_and_explain_region( + let must_outlive = note_and_explain::RegionExplanation::new( self.tcx, - &mut err, - "but lifetime must outlive ", sub, - "", None, + note_and_explain::PrefixKind::LfMustOutlive, + note_and_explain::SuffixKind::Empty, ); - err + LfBoundNotSatisfied { + span, + notes: instantiated.into_iter().chain(must_outlive).collect(), + } + .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic) } }; if sub.is_error() || sup.is_error() {