@@ -252,6 +252,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
252
252
method: &ty::AssociatedItem)
253
253
-> Option<MethodViolationCode>
254
254
{
255
+ debug!("object_safety_violation_for_method({:?}, {:?})", trait_def_id, method);
255
256
// Any method that has a `Self : Sized` requisite is otherwise
256
257
// exempt from the regulations.
257
258
if self.generics_require_sized_self(method.def_id) {
@@ -270,6 +271,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
270
271
method: &ty::AssociatedItem)
271
272
-> bool
272
273
{
274
+ debug!("is_vtable_safe_method({:?}, {:?})", trait_def_id, method);
273
275
// Any method that has a `Self : Sized` requisite can't be called.
274
276
if self.generics_require_sized_self(method.def_id) {
275
277
return false;
@@ -402,6 +404,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
402
404
fn receiver_for_self_ty(
403
405
self, receiver_ty: Ty<'tcx>, self_ty: Ty<'tcx>, method_def_id: DefId
404
406
) -> Ty<'tcx> {
407
+ debug!("receiver_for_self_ty({:?}, {:?}, {:?})", receiver_ty, self_ty, method_def_id);
405
408
let substs = Substs::for_item(self, method_def_id, |param, _| {
406
409
if param.index == 0 {
407
410
self_ty.into()
@@ -410,7 +413,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
410
413
}
411
414
});
412
415
413
- receiver_ty.subst(self, substs)
416
+ let result = receiver_ty.subst(self, substs);
417
+ debug!("receiver_for_self_ty({:?}, {:?}, {:?}) = {:?}",
418
+ receiver_ty, self_ty, method_def_id, result);
419
+ result
414
420
}
415
421
416
422
/// creates the object type for the current trait. For example,
@@ -426,18 +432,26 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
426
432
);
427
433
428
434
let mut associated_types = traits::supertraits(self, ty::Binder::dummy(trait_ref))
429
- .flat_map(|trait_ref| self.associated_items(trait_ref.def_id()))
430
- .filter(|item| item.kind == ty::AssociatedKind::Type)
435
+ .flat_map(|super_trait_ref| {
436
+ self.associated_items(super_trait_ref.def_id())
437
+ .map(move |item| (super_trait_ref, item))
438
+ })
439
+ .filter(|(_, item)| item.kind == ty::AssociatedKind::Type)
431
440
.collect::<Vec<_>>();
432
441
433
442
// existential predicates need to be in a specific order
434
- associated_types.sort_by_cached_key(|item| self.def_path_hash(item.def_id));
435
-
436
- let projection_predicates = associated_types.into_iter().map(|item| {
443
+ associated_types.sort_by_cached_key(|(_, item)| self.def_path_hash(item.def_id));
444
+
445
+ let projection_predicates = associated_types.into_iter().map(|(super_trait_ref, item)| {
446
+ // We *can* get bound lifetimes here in cases like
447
+ // `trait MyTrait: for<'s> OtherTrait<&'s T, Output=bool>`.
448
+ //
449
+ // binder moved to (*)...
450
+ let super_trait_ref = super_trait_ref.skip_binder();
437
451
ty::ExistentialPredicate::Projection(ty::ExistentialProjection {
438
- ty: self.mk_projection(item.def_id, trait_ref .substs),
452
+ ty: self.mk_projection(item.def_id, super_trait_ref .substs),
439
453
item_def_id: item.def_id,
440
- substs: trait_ref .substs,
454
+ substs: super_trait_ref .substs,
441
455
})
442
456
});
443
457
@@ -446,7 +460,8 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
446
460
);
447
461
448
462
let object_ty = self.mk_dynamic(
449
- ty::Binder::dummy(existential_predicates),
463
+ // (*) ... binder re-introduced here
464
+ ty::Binder::bind(existential_predicates),
450
465
lifetime,
451
466
);
452
467
0 commit comments