Port another diagnostic
This commit is contained in:
parent
cb8ea01096
commit
35dbec338a
3 changed files with 23 additions and 17 deletions
|
@ -146,8 +146,10 @@ infer_region_explanation = {$pref_kind ->
|
||||||
[source_pointer_valid_for] source pointer is only valid for
|
[source_pointer_valid_for] source pointer is only valid for
|
||||||
[type_satisfy] type must satisfy
|
[type_satisfy] type must satisfy
|
||||||
[type_outlive] type must outlive
|
[type_outlive] type must outlive
|
||||||
[lf_instantiated_with] lifetime parameter instantiated with
|
[lf_param_instantiated_with] lifetime parameter instantiated with
|
||||||
[lf_must_outlive] but lifetime parameter must outlive
|
[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
|
[type_valid_for] the type is valid for
|
||||||
[borrow_lasts_for] but the borrow lasts for
|
[borrow_lasts_for] but the borrow lasts for
|
||||||
[pointer_valid_for] the pointer is valid for
|
[pointer_valid_for] the pointer is valid for
|
||||||
|
|
|
@ -127,6 +127,8 @@ pub enum PrefixKind {
|
||||||
SourcePointerValidFor,
|
SourcePointerValidFor,
|
||||||
TypeSatisfy,
|
TypeSatisfy,
|
||||||
TypeOutlive,
|
TypeOutlive,
|
||||||
|
LfParamInstantiatedWith,
|
||||||
|
LfParamMustOutlive,
|
||||||
LfInstantiatedWith,
|
LfInstantiatedWith,
|
||||||
LfMustOutlive,
|
LfMustOutlive,
|
||||||
TypeValidFor,
|
TypeValidFor,
|
||||||
|
@ -151,6 +153,8 @@ impl IntoDiagnosticArg for PrefixKind {
|
||||||
Self::SourcePointerValidFor => "source_pointer_valid_for",
|
Self::SourcePointerValidFor => "source_pointer_valid_for",
|
||||||
Self::TypeSatisfy => "type_satisfy",
|
Self::TypeSatisfy => "type_satisfy",
|
||||||
Self::TypeOutlive => "type_outlive",
|
Self::TypeOutlive => "type_outlive",
|
||||||
|
Self::LfParamInstantiatedWith => "lf_param_instantiated_with",
|
||||||
|
Self::LfParamMustOutlive => "lf_param_must_outlive",
|
||||||
Self::LfInstantiatedWith => "lf_instantiated_with",
|
Self::LfInstantiatedWith => "lf_instantiated_with",
|
||||||
Self::LfMustOutlive => "lf_must_outlive",
|
Self::LfMustOutlive => "lf_must_outlive",
|
||||||
Self::TypeValidFor => "type_valid_for",
|
Self::TypeValidFor => "type_valid_for",
|
||||||
|
|
|
@ -5,8 +5,8 @@ use crate::errors::{
|
||||||
use crate::infer::error_reporting::{note_and_explain_region, TypeErrCtxt};
|
use crate::infer::error_reporting::{note_and_explain_region, TypeErrCtxt};
|
||||||
use crate::infer::{self, SubregionOrigin};
|
use crate::infer::{self, SubregionOrigin};
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
fluent, struct_span_err, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder,
|
fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
|
||||||
ErrorGuaranteed, IntoDiagnostic,
|
IntoDiagnostic,
|
||||||
};
|
};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_middle::traits::ObligationCauseCode;
|
use rustc_middle::traits::ObligationCauseCode;
|
||||||
|
@ -184,14 +184,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
self.tcx,
|
self.tcx,
|
||||||
sup,
|
sup,
|
||||||
None,
|
None,
|
||||||
note_and_explain::PrefixKind::LfInstantiatedWith,
|
note_and_explain::PrefixKind::LfParamInstantiatedWith,
|
||||||
note_and_explain::SuffixKind::Empty,
|
note_and_explain::SuffixKind::Empty,
|
||||||
);
|
);
|
||||||
let param_must_outlive = note_and_explain::RegionExplanation::new(
|
let param_must_outlive = note_and_explain::RegionExplanation::new(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
sub,
|
sub,
|
||||||
None,
|
None,
|
||||||
note_and_explain::PrefixKind::LfMustOutlive,
|
note_and_explain::PrefixKind::LfParamMustOutlive,
|
||||||
note_and_explain::SuffixKind::Empty,
|
note_and_explain::SuffixKind::Empty,
|
||||||
);
|
);
|
||||||
LfBoundNotSatisfied {
|
LfBoundNotSatisfied {
|
||||||
|
@ -279,25 +279,25 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
infer::AscribeUserTypeProvePredicate(span) => {
|
infer::AscribeUserTypeProvePredicate(span) => {
|
||||||
let mut err =
|
let instantiated = note_and_explain::RegionExplanation::new(
|
||||||
struct_span_err!(self.tcx.sess, span, E0478, "lifetime bound not satisfied");
|
|
||||||
note_and_explain_region(
|
|
||||||
self.tcx,
|
self.tcx,
|
||||||
&mut err,
|
|
||||||
"lifetime instantiated with ",
|
|
||||||
sup,
|
sup,
|
||||||
"",
|
|
||||||
None,
|
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,
|
self.tcx,
|
||||||
&mut err,
|
|
||||||
"but lifetime must outlive ",
|
|
||||||
sub,
|
sub,
|
||||||
"",
|
|
||||||
None,
|
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() {
|
if sub.is_error() || sup.is_error() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue