Skip to content

Commit

Permalink
Port another diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
IntQuant committed Feb 14, 2023
1 parent cb8ea01 commit 35dbec3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_error_messages/locales/en-US/infer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_infer/src/errors/note_and_explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ pub enum PrefixKind {
SourcePointerValidFor,
TypeSatisfy,
TypeOutlive,
LfParamInstantiatedWith,
LfParamMustOutlive,
LfInstantiatedWith,
LfMustOutlive,
TypeValidFor,
Expand All @@ -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",
Expand Down
30 changes: 15 additions & 15 deletions compiler/rustc_infer/src/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 35dbec3

Please sign in to comment.