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