@@ -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 ;
@@ -389,6 +391,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
389
391
fn receiver_for_self_ty (
390
392
self , receiver_ty : Ty < ' tcx > , self_ty : Ty < ' tcx > , method_def_id : DefId
391
393
) -> Ty < ' tcx > {
394
+ debug ! ( "receiver_for_self_ty({:?}, {:?}, {:?})" , receiver_ty, self_ty, method_def_id) ;
392
395
let substs = Substs :: for_item ( self , method_def_id, |param, _| {
393
396
if param. index == 0 {
394
397
self_ty. into ( )
@@ -397,7 +400,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
397
400
}
398
401
} ) ;
399
402
400
- receiver_ty. subst ( self , substs)
403
+ let result = receiver_ty. subst ( self , substs) ;
404
+ debug ! ( "receiver_for_self_ty({:?}, {:?}, {:?}) = {:?}" ,
405
+ receiver_ty, self_ty, method_def_id, result) ;
406
+ result
401
407
}
402
408
403
409
/// creates the object type for the current trait. For example,
@@ -413,18 +419,26 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
413
419
) ;
414
420
415
421
let mut associated_types = traits:: supertraits ( self , ty:: Binder :: dummy ( trait_ref) )
416
- . flat_map ( |trait_ref| self . associated_items ( trait_ref. def_id ( ) ) )
417
- . filter ( |item| item. kind == ty:: AssociatedKind :: Type )
422
+ . flat_map ( |super_trait_ref| {
423
+ self . associated_items ( super_trait_ref. def_id ( ) )
424
+ . map ( move |item| ( super_trait_ref, item) )
425
+ } )
426
+ . filter ( |( _, item) | item. kind == ty:: AssociatedKind :: Type )
418
427
. collect :: < Vec < _ > > ( ) ;
419
428
420
429
// existential predicates need to be in a specific order
421
- associated_types. sort_by_cached_key ( |item| self . def_path_hash ( item. def_id ) ) ;
422
-
423
- let projection_predicates = associated_types. into_iter ( ) . map ( |item| {
430
+ associated_types. sort_by_cached_key ( |( _, item) | self . def_path_hash ( item. def_id ) ) ;
431
+
432
+ let projection_predicates = associated_types. into_iter ( ) . map ( |( super_trait_ref, item) | {
433
+ // We *can* get bound lifetimes here in cases like
434
+ // `trait MyTrait: for<'s> OtherTrait<&'s T, Output=bool>`.
435
+ //
436
+ // binder moved to (*)...
437
+ let super_trait_ref = super_trait_ref. skip_binder ( ) ;
424
438
ty:: ExistentialPredicate :: Projection ( ty:: ExistentialProjection {
425
- ty : self . mk_projection ( item. def_id , trait_ref . substs ) ,
439
+ ty : self . mk_projection ( item. def_id , super_trait_ref . substs ) ,
426
440
item_def_id : item. def_id ,
427
- substs : trait_ref . substs ,
441
+ substs : super_trait_ref . substs ,
428
442
} )
429
443
} ) ;
430
444
@@ -433,7 +447,8 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
433
447
) ;
434
448
435
449
let object_ty = self . mk_dynamic (
436
- ty:: Binder :: dummy ( existential_predicates) ,
450
+ // (*) ... binder re-introduced here
451
+ ty:: Binder :: bind ( existential_predicates) ,
437
452
lifetime,
438
453
) ;
439
454
0 commit comments