Skip to content

Commit 61c777b

Browse files
committed
introduce new origin for Trait+'b
This helps us to preserve the existing errors.
1 parent a20b062 commit 61c777b

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
868868
err.note(&format!("required so that reference `{}` does not outlive its referent",
869869
ref_ty));
870870
}
871+
ObligationCauseCode::ObjectTypeBound(object_ty, region) => {
872+
err.note(&format!("required so that the lifetime bound of `{}` for `{}` \
873+
is satisfied",
874+
region, object_ty));
875+
}
871876
ObligationCauseCode::ItemObligation(item_def_id) => {
872877
let item_name = tcx.item_path_str(item_def_id);
873878
err.note(&format!("required by `{}`", item_name));

src/librustc/traits/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ pub enum ObligationCauseCode<'tcx> {
111111
/// A type like `&'a T` is WF only if `T: 'a`.
112112
ReferenceOutlivesReferent(Ty<'tcx>),
113113

114+
/// A type like `Box<Foo<'a> + 'b>` is WF only if `'b: 'a`.
115+
ObjectTypeBound(Ty<'tcx>, &'tcx ty::Region),
116+
114117
/// Obligation incurred due to an object cast.
115118
ObjectCastObligation(/* Object type */ Ty<'tcx>),
116119

src/librustc/traits/structural_impls.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
175175
super::ReferenceOutlivesReferent(ty) => {
176176
tcx.lift(&ty).map(super::ReferenceOutlivesReferent)
177177
}
178+
super::ObjectTypeBound(ty, r) => {
179+
tcx.lift(&ty).and_then(|ty| {
180+
tcx.lift(&r).and_then(|r| {
181+
Some(super::ObjectTypeBound(ty, r))
182+
})
183+
})
184+
}
178185
super::ObjectCastObligation(ty) => {
179186
tcx.lift(&ty).map(super::ObjectCastObligation)
180187
}
@@ -473,6 +480,9 @@ impl<'tcx> TypeFoldable<'tcx> for traits::ObligationCauseCode<'tcx> {
473480
super::ReferenceOutlivesReferent(ty) => {
474481
super::ReferenceOutlivesReferent(ty.fold_with(folder))
475482
}
483+
super::ObjectTypeBound(ty, r) => {
484+
super::ObjectTypeBound(ty.fold_with(folder), r.fold_with(folder))
485+
}
476486
super::ObjectCastObligation(ty) => {
477487
super::ObjectCastObligation(ty.fold_with(folder))
478488
}
@@ -504,6 +514,7 @@ impl<'tcx> TypeFoldable<'tcx> for traits::ObligationCauseCode<'tcx> {
504514

505515
super::ProjectionWf(proj) => proj.visit_with(visitor),
506516
super::ReferenceOutlivesReferent(ty) => ty.visit_with(visitor),
517+
super::ObjectTypeBound(ty, r) => ty.visit_with(visitor) || r.visit_with(visitor),
507518
super::ObjectCastObligation(ty) => ty.visit_with(visitor),
508519
super::BuiltinDerivedObligation(ref cause) => cause.visit_with(visitor),
509520
super::ImplDerivedObligation(ref cause) => cause.visit_with(visitor)

src/librustc/ty/wf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
498498
let explicit_bound = data.region_bound;
499499

500500
for implicit_bound in implicit_bounds {
501-
let cause = self.cause(traits::ReferenceOutlivesReferent(ty));
501+
let cause = self.cause(traits::ObjectTypeBound(ty, explicit_bound));
502502
let outlives = ty::Binder(ty::OutlivesPredicate(explicit_bound, implicit_bound));
503503
self.out.push(traits::Obligation::new(cause, outlives.to_predicate()));
504504
}

0 commit comments

Comments
 (0)