Port RefLongerThanData
This commit is contained in:
parent
58e901b6fd
commit
cb8ea01096
4 changed files with 30 additions and 17 deletions
|
@ -150,6 +150,8 @@ infer_region_explanation = {$pref_kind ->
|
||||||
[lf_must_outlive] but lifetime parameter must outlive
|
[lf_must_outlive] but lifetime parameter 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
|
||||||
|
[data_valid_for] but the referenced data is only valid for
|
||||||
[empty] {""}
|
[empty] {""}
|
||||||
}{$pref_kind ->
|
}{$pref_kind ->
|
||||||
[empty] {""}
|
[empty] {""}
|
||||||
|
@ -175,6 +177,7 @@ infer_outlives_bound = lifetime of the source pointer does not outlive lifetime
|
||||||
infer_fullfill_req_lifetime = the type `{$ty}` does not fulfill the required lifetime
|
infer_fullfill_req_lifetime = the type `{$ty}` does not fulfill the required lifetime
|
||||||
infer_lf_bound_not_satisfied = lifetime bound not satisfied
|
infer_lf_bound_not_satisfied = lifetime bound not satisfied
|
||||||
infer_borrowed_too_long = a value of type `{$ty}` is borrowed for too long
|
infer_borrowed_too_long = a value of type `{$ty}` is borrowed for too long
|
||||||
|
infer_ref_longer_than_data = in type `{$ty}`, reference has a longer lifetime than the data it references
|
||||||
|
|
||||||
infer_mismatched_static_lifetime = incompatible lifetime on type
|
infer_mismatched_static_lifetime = incompatible lifetime on type
|
||||||
infer_does_not_outlive_static_from_impl = ...does not necessarily outlive the static lifetime introduced by the compatible `impl`
|
infer_does_not_outlive_static_from_impl = ...does not necessarily outlive the static lifetime introduced by the compatible `impl`
|
||||||
|
|
|
@ -980,3 +980,13 @@ pub struct BorrowedTooLong<'a> {
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
|
pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(infer_ref_longer_than_data, code = "E0491")]
|
||||||
|
pub struct RefLongerThanData<'a> {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub ty: Ty<'a>,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
|
||||||
|
}
|
||||||
|
|
|
@ -131,6 +131,8 @@ pub enum PrefixKind {
|
||||||
LfMustOutlive,
|
LfMustOutlive,
|
||||||
TypeValidFor,
|
TypeValidFor,
|
||||||
BorrowLastsFor,
|
BorrowLastsFor,
|
||||||
|
PointerValidFor,
|
||||||
|
DataValidFor,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum SuffixKind {
|
pub enum SuffixKind {
|
||||||
|
@ -153,6 +155,8 @@ impl IntoDiagnosticArg for PrefixKind {
|
||||||
Self::LfMustOutlive => "lf_must_outlive",
|
Self::LfMustOutlive => "lf_must_outlive",
|
||||||
Self::TypeValidFor => "type_valid_for",
|
Self::TypeValidFor => "type_valid_for",
|
||||||
Self::BorrowLastsFor => "borrow_lasts_for",
|
Self::BorrowLastsFor => "borrow_lasts_for",
|
||||||
|
Self::PointerValidFor => "pointer_valid_for",
|
||||||
|
Self::DataValidFor => "data_valid_for",
|
||||||
}
|
}
|
||||||
.into();
|
.into();
|
||||||
rustc_errors::DiagnosticArgValue::Str(kind)
|
rustc_errors::DiagnosticArgValue::Str(kind)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
note_and_explain, BorrowedTooLong, FullfillReqLifetime, LfBoundNotSatisfied, OutlivesBound,
|
note_and_explain, BorrowedTooLong, FullfillReqLifetime, LfBoundNotSatisfied, OutlivesBound,
|
||||||
OutlivesContent, RegionOriginNote,
|
OutlivesContent, RefLongerThanData, RegionOriginNote,
|
||||||
};
|
};
|
||||||
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};
|
||||||
|
@ -223,30 +223,26 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
|
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
|
||||||
}
|
}
|
||||||
infer::ReferenceOutlivesReferent(ty, span) => {
|
infer::ReferenceOutlivesReferent(ty, span) => {
|
||||||
let mut err = struct_span_err!(
|
let pointer_valid = note_and_explain::RegionExplanation::new(
|
||||||
self.tcx.sess,
|
|
||||||
span,
|
|
||||||
E0491,
|
|
||||||
"in type `{}`, reference has a longer lifetime than the data it references",
|
|
||||||
self.ty_to_string(ty)
|
|
||||||
);
|
|
||||||
note_and_explain_region(
|
|
||||||
self.tcx,
|
self.tcx,
|
||||||
&mut err,
|
|
||||||
"the pointer is valid for ",
|
|
||||||
sub,
|
sub,
|
||||||
"",
|
|
||||||
None,
|
None,
|
||||||
|
note_and_explain::PrefixKind::PointerValidFor,
|
||||||
|
note_and_explain::SuffixKind::Empty,
|
||||||
);
|
);
|
||||||
note_and_explain_region(
|
let data_valid = note_and_explain::RegionExplanation::new(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
&mut err,
|
|
||||||
"but the referenced data is only valid for ",
|
|
||||||
sup,
|
sup,
|
||||||
"",
|
|
||||||
None,
|
None,
|
||||||
|
note_and_explain::PrefixKind::DataValidFor,
|
||||||
|
note_and_explain::SuffixKind::Empty,
|
||||||
);
|
);
|
||||||
err
|
RefLongerThanData {
|
||||||
|
span,
|
||||||
|
ty: self.resolve_vars_if_possible(ty),
|
||||||
|
notes: pointer_valid.into_iter().chain(data_valid).collect(),
|
||||||
|
}
|
||||||
|
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
|
||||||
}
|
}
|
||||||
infer::CompareImplItemObligation { span, impl_item_def_id, trait_item_def_id } => {
|
infer::CompareImplItemObligation { span, impl_item_def_id, trait_item_def_id } => {
|
||||||
let mut err = self.report_extra_impl_obligation(
|
let mut err = self.report_extra_impl_obligation(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue