1
Fork 0

Add AscribeUserTypeProvePredicate

This commit is contained in:
Jack Huey 2022-09-16 17:20:11 -04:00
parent ec17be2656
commit 9929c0ac76
5 changed files with 48 additions and 2 deletions

View file

@ -110,6 +110,7 @@ infer_relate_param_bound = ...so that the type `{$name}` will meet its required
infer_relate_param_bound_2 = ...that is required by this bound infer_relate_param_bound_2 = ...that is required by this bound
infer_relate_region_param_bound = ...so that the declared lifetime parameter bounds are satisfied infer_relate_region_param_bound = ...so that the declared lifetime parameter bounds are satisfied
infer_compare_impl_item_obligation = ...so that the definition in impl matches the definition from the trait infer_compare_impl_item_obligation = ...so that the definition in impl matches the definition from the trait
infer_ascribe_user_type_prove_predicate = ...so that the where clause holds
infer_nothing = {""} infer_nothing = {""}

View file

@ -77,6 +77,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
infer::CheckAssociatedTypeBounds { ref parent, .. } => { infer::CheckAssociatedTypeBounds { ref parent, .. } => {
self.note_region_origin(err, &parent); self.note_region_origin(err, &parent);
} }
infer::AscribeUserTypeProvePredicate(span) => {
RegionOriginNote::Plain {
span,
msg: fluent::infer::ascribe_user_type_prove_predicate,
}
.add_to_diagnostic(err);
}
} }
} }
@ -356,6 +363,27 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
err err
} }
infer::AscribeUserTypeProvePredicate(span) => {
let mut err =
struct_span_err!(self.tcx.sess, span, E0478, "lifetime bound not satisfied");
note_and_explain_region(
self.tcx,
&mut err,
"lifetime instantiated with ",
sup,
"",
None,
);
note_and_explain_region(
self.tcx,
&mut err,
"but lifetime must outlive ",
sub,
"",
None,
);
err
}
} }
} }

View file

@ -409,7 +409,11 @@ pub enum SubregionOrigin<'tcx> {
/// Comparing the signature and requirements of an impl method against /// Comparing the signature and requirements of an impl method against
/// the containing trait. /// the containing trait.
CompareImplItemObligation { span: Span, impl_item_def_id: LocalDefId, trait_item_def_id: DefId }, CompareImplItemObligation {
span: Span,
impl_item_def_id: LocalDefId,
trait_item_def_id: DefId,
},
/// Checking that the bounds of a trait's associated type hold for a given impl /// Checking that the bounds of a trait's associated type hold for a given impl
CheckAssociatedTypeBounds { CheckAssociatedTypeBounds {
@ -417,6 +421,8 @@ pub enum SubregionOrigin<'tcx> {
impl_item_def_id: LocalDefId, impl_item_def_id: LocalDefId,
trait_item_def_id: DefId, trait_item_def_id: DefId,
}, },
AscribeUserTypeProvePredicate(Span),
} }
// `SubregionOrigin` is used a lot. Make sure it doesn't unintentionally get bigger. // `SubregionOrigin` is used a lot. Make sure it doesn't unintentionally get bigger.
@ -2001,6 +2007,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
DataBorrowed(_, a) => a, DataBorrowed(_, a) => a,
ReferenceOutlivesReferent(_, a) => a, ReferenceOutlivesReferent(_, a) => a,
CompareImplItemObligation { span, .. } => span, CompareImplItemObligation { span, .. } => span,
AscribeUserTypeProvePredicate(span) => span,
CheckAssociatedTypeBounds { ref parent, .. } => parent.span(), CheckAssociatedTypeBounds { ref parent, .. } => parent.span(),
} }
} }
@ -2033,6 +2040,10 @@ impl<'tcx> SubregionOrigin<'tcx> {
parent: Box::new(default()), parent: Box::new(default()),
}, },
traits::ObligationCauseCode::AscribeUserTypeProvePredicate(span) => {
SubregionOrigin::AscribeUserTypeProvePredicate(span)
}
_ => default(), _ => default(),
} }
} }

View file

@ -188,6 +188,9 @@ impl<'tcx> ObligationCause<'tcx> {
pub fn to_constraint_category(&self) -> ConstraintCategory<'tcx> { pub fn to_constraint_category(&self) -> ConstraintCategory<'tcx> {
match self.code() { match self.code() {
MatchImpl(cause, _) => cause.to_constraint_category(), MatchImpl(cause, _) => cause.to_constraint_category(),
AscribeUserTypeProvePredicate(predicate_span) => {
ConstraintCategory::Predicate(*predicate_span)
}
_ => ConstraintCategory::BoringNoLocation, _ => ConstraintCategory::BoringNoLocation,
} }
} }
@ -426,6 +429,8 @@ pub enum ObligationCauseCode<'tcx> {
is_lit: bool, is_lit: bool,
output_ty: Option<Ty<'tcx>>, output_ty: Option<Ty<'tcx>>,
}, },
AscribeUserTypeProvePredicate(Span),
} }
/// The 'location' at which we try to perform HIR-based wf checking. /// The 'location' at which we try to perform HIR-based wf checking.

View file

@ -2256,7 +2256,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
| ObligationCauseCode::QuestionMark | ObligationCauseCode::QuestionMark
| ObligationCauseCode::CheckAssociatedTypeBounds { .. } | ObligationCauseCode::CheckAssociatedTypeBounds { .. }
| ObligationCauseCode::LetElse | ObligationCauseCode::LetElse
| ObligationCauseCode::BinOp { .. } => {} | ObligationCauseCode::BinOp { .. }
| ObligationCauseCode::AscribeUserTypeProvePredicate(..) => {}
ObligationCauseCode::SliceOrArrayElem => { ObligationCauseCode::SliceOrArrayElem => {
err.note("slice and array elements must have `Sized` type"); err.note("slice and array elements must have `Sized` type");
} }