@@ -18,7 +18,7 @@ use middle::fast_reject;
18
18
use middle:: subst;
19
19
use middle:: subst:: Subst ;
20
20
use middle:: traits;
21
- use middle:: ty:: { self , Ty , ToPolyTraitRef } ;
21
+ use middle:: ty:: { self , RegionEscape , Ty , ToPolyTraitRef } ;
22
22
use middle:: ty_fold:: TypeFoldable ;
23
23
use middle:: infer;
24
24
use middle:: infer:: InferCtxt ;
@@ -309,18 +309,20 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
309
309
// argument type like `&Trait`.
310
310
let trait_ref = data. principal_trait_ref_with_self_ty ( self . tcx ( ) , self_ty) ;
311
311
self . elaborate_bounds ( & [ trait_ref. clone ( ) ] , false , |this, new_trait_ref, m, method_num| {
312
+ let new_trait_ref = this. erase_late_bound_regions ( & new_trait_ref) ;
313
+
312
314
let vtable_index =
313
315
traits:: get_vtable_index_of_object_method ( tcx,
314
316
trait_ref. clone ( ) ,
315
- new_trait_ref. def_id ( ) ,
317
+ new_trait_ref. def_id ,
316
318
method_num) ;
317
319
318
- let xform_self_ty = this. xform_self_ty ( & m, new_trait_ref. substs ( ) ) ;
320
+ let xform_self_ty = this. xform_self_ty ( & m, new_trait_ref. substs ) ;
319
321
320
322
this. inherent_candidates . push ( Candidate {
321
323
xform_self_ty : xform_self_ty,
322
324
method_ty : m,
323
- kind : ObjectCandidate ( new_trait_ref. def_id ( ) , method_num, vtable_index)
325
+ kind : ObjectCandidate ( new_trait_ref. def_id , method_num, vtable_index)
324
326
} ) ;
325
327
} ) ;
326
328
}
@@ -353,34 +355,37 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
353
355
} )
354
356
. collect ( ) ;
355
357
356
- self . elaborate_bounds ( bounds. as_slice ( ) , true , |this, trait_ref, m, method_num| {
358
+ self . elaborate_bounds ( bounds. as_slice ( ) , true , |this, poly_trait_ref, m, method_num| {
359
+ let trait_ref =
360
+ this. erase_late_bound_regions ( & poly_trait_ref) ;
361
+
357
362
let xform_self_ty =
358
- this. xform_self_ty ( & m, trait_ref. substs ( ) ) ;
363
+ this. xform_self_ty ( & m, trait_ref. substs ) ;
359
364
360
365
debug ! ( "found match: trait_ref={} substs={} m={}" ,
361
366
trait_ref. repr( this. tcx( ) ) ,
362
- trait_ref. substs( ) . repr( this. tcx( ) ) ,
367
+ trait_ref. substs. repr( this. tcx( ) ) ,
363
368
m. repr( this. tcx( ) ) ) ;
364
369
assert_eq ! ( m. generics. types. get_slice( subst:: TypeSpace ) . len( ) ,
365
- trait_ref. substs( ) . types. get_slice( subst:: TypeSpace ) . len( ) ) ;
370
+ trait_ref. substs. types. get_slice( subst:: TypeSpace ) . len( ) ) ;
366
371
assert_eq ! ( m. generics. regions. get_slice( subst:: TypeSpace ) . len( ) ,
367
- trait_ref. substs( ) . regions( ) . get_slice( subst:: TypeSpace ) . len( ) ) ;
372
+ trait_ref. substs. regions( ) . get_slice( subst:: TypeSpace ) . len( ) ) ;
368
373
assert_eq ! ( m. generics. types. get_slice( subst:: SelfSpace ) . len( ) ,
369
- trait_ref. substs( ) . types. get_slice( subst:: SelfSpace ) . len( ) ) ;
374
+ trait_ref. substs. types. get_slice( subst:: SelfSpace ) . len( ) ) ;
370
375
assert_eq ! ( m. generics. regions. get_slice( subst:: SelfSpace ) . len( ) ,
371
- trait_ref. substs( ) . regions( ) . get_slice( subst:: SelfSpace ) . len( ) ) ;
376
+ trait_ref. substs. regions( ) . get_slice( subst:: SelfSpace ) . len( ) ) ;
372
377
373
378
// Because this trait derives from a where-clause, it
374
379
// should not contain any inference variables or other
375
380
// artifacts. This means it is safe to put into the
376
381
// `WhereClauseCandidate` and (eventually) into the
377
382
// `WhereClausePick`.
378
- assert ! ( trait_ref. substs( ) . types. iter( ) . all( |& t| !ty:: type_needs_infer( t) ) ) ;
383
+ assert ! ( trait_ref. substs. types. iter( ) . all( |& t| !ty:: type_needs_infer( t) ) ) ;
379
384
380
385
this. inherent_candidates . push ( Candidate {
381
386
xform_self_ty : xform_self_ty,
382
387
method_ty : m,
383
- kind : WhereClauseCandidate ( trait_ref , method_num)
388
+ kind : WhereClauseCandidate ( poly_trait_ref , method_num)
384
389
} ) ;
385
390
} ) ;
386
391
}
@@ -614,11 +619,12 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
614
619
// Check whether there are any where-clauses pertaining to this trait.
615
620
let caller_predicates =
616
621
self . fcx . inh . param_env . caller_bounds . predicates . as_slice ( ) . to_vec ( ) ;
617
- for bound in traits:: elaborate_predicates ( self . tcx ( ) , caller_predicates)
618
- . filter_map ( |p| p. to_opt_poly_trait_ref ( ) )
619
- . filter ( |b| b. def_id ( ) == trait_def_id)
622
+ for poly_bound in traits:: elaborate_predicates ( self . tcx ( ) , caller_predicates)
623
+ . filter_map ( |p| p. to_opt_poly_trait_ref ( ) )
624
+ . filter ( |b| b. def_id ( ) == trait_def_id)
620
625
{
621
- let xform_self_ty = self . xform_self_ty ( & method_ty, bound. substs ( ) ) ;
626
+ let bound = self . erase_late_bound_regions ( & poly_bound) ;
627
+ let xform_self_ty = self . xform_self_ty ( & method_ty, bound. substs ) ;
622
628
623
629
debug ! ( "assemble_where_clause_candidates: bound={} xform_self_ty={}" ,
624
630
bound. repr( self . tcx( ) ) ,
@@ -627,7 +633,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
627
633
self . extension_candidates . push ( Candidate {
628
634
xform_self_ty : xform_self_ty,
629
635
method_ty : method_ty. clone ( ) ,
630
- kind : WhereClauseCandidate ( bound , method_index)
636
+ kind : WhereClauseCandidate ( poly_bound , method_index)
631
637
} ) ;
632
638
}
633
639
}
@@ -920,6 +926,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
920
926
method. fty. sig. 0 . inputs[ 0 ] . repr( self . tcx( ) ) ,
921
927
substs. repr( self . tcx( ) ) ) ;
922
928
929
+ assert ! ( !substs. has_escaping_regions( ) ) ;
930
+
923
931
// It is possible for type parameters or early-bound lifetimes
924
932
// to appear in the signature of `self`. The substitutions we
925
933
// are given do not include type/lifetime parameters for the
@@ -949,14 +957,13 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
949
957
substs = & placeholder;
950
958
}
951
959
952
- // Replace early-bound regions and types.
953
- let xform_self_ty = method. fty . sig . 0 . inputs [ 0 ] . subst ( self . tcx ( ) , substs) ;
960
+ // Erase any late-bound regions from the method and substitute
961
+ // in the values from the substitution.
962
+ let xform_self_ty = method. fty . sig . input ( 0 ) ;
963
+ let xform_self_ty = self . erase_late_bound_regions ( & xform_self_ty) ;
964
+ let xform_self_ty = xform_self_ty. subst ( self . tcx ( ) , substs) ;
954
965
955
- // Replace late-bound regions bound in the impl or
956
- // where-clause (2 levels of binding) and method (1 level of binding).
957
- self . erase_late_bound_regions (
958
- & self . erase_late_bound_regions (
959
- & ty:: Binder ( ty:: Binder ( xform_self_ty) ) ) )
966
+ xform_self_ty
960
967
}
961
968
962
969
fn impl_substs ( & self ,
0 commit comments