Skip to content

Commit 9929c0a

Browse files
committed
Add AscribeUserTypeProvePredicate
1 parent ec17be2 commit 9929c0a

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

compiler/rustc_error_messages/locales/en-US/infer.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ infer_relate_param_bound = ...so that the type `{$name}` will meet its required
110110
infer_relate_param_bound_2 = ...that is required by this bound
111111
infer_relate_region_param_bound = ...so that the declared lifetime parameter bounds are satisfied
112112
infer_compare_impl_item_obligation = ...so that the definition in impl matches the definition from the trait
113+
infer_ascribe_user_type_prove_predicate = ...so that the where clause holds
113114
114115
infer_nothing = {""}
115116

compiler/rustc_infer/src/infer/error_reporting/note.rs

+28
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
7777
infer::CheckAssociatedTypeBounds { ref parent, .. } => {
7878
self.note_region_origin(err, &parent);
7979
}
80+
infer::AscribeUserTypeProvePredicate(span) => {
81+
RegionOriginNote::Plain {
82+
span,
83+
msg: fluent::infer::ascribe_user_type_prove_predicate,
84+
}
85+
.add_to_diagnostic(err);
86+
}
8087
}
8188
}
8289

@@ -356,6 +363,27 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
356363

357364
err
358365
}
366+
infer::AscribeUserTypeProvePredicate(span) => {
367+
let mut err =
368+
struct_span_err!(self.tcx.sess, span, E0478, "lifetime bound not satisfied");
369+
note_and_explain_region(
370+
self.tcx,
371+
&mut err,
372+
"lifetime instantiated with ",
373+
sup,
374+
"",
375+
None,
376+
);
377+
note_and_explain_region(
378+
self.tcx,
379+
&mut err,
380+
"but lifetime must outlive ",
381+
sub,
382+
"",
383+
None,
384+
);
385+
err
386+
}
359387
}
360388
}
361389

compiler/rustc_infer/src/infer/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,20 @@ pub enum SubregionOrigin<'tcx> {
409409

410410
/// Comparing the signature and requirements of an impl method against
411411
/// the containing trait.
412-
CompareImplItemObligation { span: Span, impl_item_def_id: LocalDefId, trait_item_def_id: DefId },
412+
CompareImplItemObligation {
413+
span: Span,
414+
impl_item_def_id: LocalDefId,
415+
trait_item_def_id: DefId,
416+
},
413417

414418
/// Checking that the bounds of a trait's associated type hold for a given impl
415419
CheckAssociatedTypeBounds {
416420
parent: Box<SubregionOrigin<'tcx>>,
417421
impl_item_def_id: LocalDefId,
418422
trait_item_def_id: DefId,
419423
},
424+
425+
AscribeUserTypeProvePredicate(Span),
420426
}
421427

422428
// `SubregionOrigin` is used a lot. Make sure it doesn't unintentionally get bigger.
@@ -2001,6 +2007,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
20012007
DataBorrowed(_, a) => a,
20022008
ReferenceOutlivesReferent(_, a) => a,
20032009
CompareImplItemObligation { span, .. } => span,
2010+
AscribeUserTypeProvePredicate(span) => span,
20042011
CheckAssociatedTypeBounds { ref parent, .. } => parent.span(),
20052012
}
20062013
}
@@ -2033,6 +2040,10 @@ impl<'tcx> SubregionOrigin<'tcx> {
20332040
parent: Box::new(default()),
20342041
},
20352042

2043+
traits::ObligationCauseCode::AscribeUserTypeProvePredicate(span) => {
2044+
SubregionOrigin::AscribeUserTypeProvePredicate(span)
2045+
}
2046+
20362047
_ => default(),
20372048
}
20382049
}

compiler/rustc_middle/src/traits/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ impl<'tcx> ObligationCause<'tcx> {
188188
pub fn to_constraint_category(&self) -> ConstraintCategory<'tcx> {
189189
match self.code() {
190190
MatchImpl(cause, _) => cause.to_constraint_category(),
191+
AscribeUserTypeProvePredicate(predicate_span) => {
192+
ConstraintCategory::Predicate(*predicate_span)
193+
}
191194
_ => ConstraintCategory::BoringNoLocation,
192195
}
193196
}
@@ -426,6 +429,8 @@ pub enum ObligationCauseCode<'tcx> {
426429
is_lit: bool,
427430
output_ty: Option<Ty<'tcx>>,
428431
},
432+
433+
AscribeUserTypeProvePredicate(Span),
429434
}
430435

431436
/// The 'location' at which we try to perform HIR-based wf checking.

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
22562256
| ObligationCauseCode::QuestionMark
22572257
| ObligationCauseCode::CheckAssociatedTypeBounds { .. }
22582258
| ObligationCauseCode::LetElse
2259-
| ObligationCauseCode::BinOp { .. } => {}
2259+
| ObligationCauseCode::BinOp { .. }
2260+
| ObligationCauseCode::AscribeUserTypeProvePredicate(..) => {}
22602261
ObligationCauseCode::SliceOrArrayElem => {
22612262
err.note("slice and array elements must have `Sized` type");
22622263
}

0 commit comments

Comments
 (0)