@@ -99,7 +99,10 @@ fn lookup(
99
99
inherent_candidates : DVec ( ) ,
100
100
extension_candidates : DVec ( )
101
101
} ;
102
- return lcx. do_lookup ( self_ty) ;
102
+ let mme = lcx. do_lookup ( self_ty) ;
103
+ debug ! ( "method lookup for %s yielded %?" ,
104
+ expr_repr( fcx. tcx( ) , expr) , mme) ;
105
+ return move mme;
103
106
}
104
107
105
108
struct LookupContext {
@@ -333,6 +336,10 @@ impl LookupContext {
333
336
let rcvr_ty = ty:: mk_param ( tcx, param_ty. idx , param_ty. def_id ) ;
334
337
let rcvr_substs = { self_ty : Some ( rcvr_ty) , ..bound_substs} ;
335
338
339
+ let ( rcvr_ty, rcvr_substs) =
340
+ self . create_rcvr_ty_and_substs_for_method (
341
+ method. self_ty , rcvr_ty, move rcvr_substs) ;
342
+
336
343
self . inherent_candidates . push ( Candidate {
337
344
rcvr_ty : rcvr_ty,
338
345
rcvr_substs : rcvr_substs,
@@ -384,8 +391,12 @@ impl LookupContext {
384
391
// candidate be selected if the method refers to `self`.
385
392
let rcvr_substs = { self_ty : Some ( self_ty) , ..* substs} ;
386
393
394
+ let ( rcvr_ty, rcvr_substs) =
395
+ self . create_rcvr_ty_and_substs_for_method (
396
+ method. self_ty , self_ty, move rcvr_substs) ;
397
+
387
398
self . inherent_candidates . push ( Candidate {
388
- rcvr_ty : self_ty ,
399
+ rcvr_ty : rcvr_ty ,
389
400
rcvr_substs : move rcvr_substs,
390
401
num_method_tps : method. tps . len ( ) ,
391
402
self_mode : get_mode_from_self_type ( method. self_ty ) ,
@@ -424,18 +435,14 @@ impl LookupContext {
424
435
let tcx = self . tcx ( ) ;
425
436
let method = & impl_info. methods [ idx] ;
426
437
427
- let need_rp = match method. self_type {
428
- ast:: sty_region( _) => true ,
429
- _ => false
430
- } ;
431
-
432
438
// determine the `self` of the impl with fresh
433
439
// variables for each parameter:
434
440
let { substs: impl_substs , ty: impl_ty} =
435
- impl_self_ty ( self . fcx , self . self_expr , impl_info. did , need_rp ) ;
441
+ impl_self_ty ( self . fcx , self . self_expr , impl_info. did ) ;
436
442
437
- let impl_ty = transform_self_type_for_method (
438
- tcx, impl_substs. self_r , impl_ty, method. self_type ) ;
443
+ let ( impl_ty, impl_substs) =
444
+ self . create_rcvr_ty_and_substs_for_method (
445
+ method. self_type , impl_ty, move impl_substs) ;
439
446
440
447
candidates. push ( Candidate {
441
448
rcvr_ty : impl_ty,
@@ -446,6 +453,48 @@ impl LookupContext {
446
453
} ) ;
447
454
}
448
455
456
+ fn create_rcvr_ty_and_substs_for_method ( & self ,
457
+ self_decl : ast:: self_ty_ ,
458
+ self_ty : ty:: t ,
459
+ +self_substs : ty:: substs )
460
+ -> ( ty:: t , ty:: substs )
461
+ {
462
+ // If the self type includes a region (like &self), we need to
463
+ // ensure that the receiver substitutions have a self region.
464
+ // If the receiver type does not itself contain borrowed
465
+ // pointers, there may not be one yet.
466
+ //
467
+ // FIXME(#3446)--this awkward situation comes about because
468
+ // the regions in the receiver are substituted before (and
469
+ // differently from) those in the argument types. This
470
+ // shouldn't really have to be.
471
+ let rcvr_substs = {
472
+ match self_decl {
473
+ sty_static | sty_value | sty_by_ref |
474
+ sty_box( _) | sty_uniq( _) => {
475
+ move self_substs
476
+ }
477
+ sty_region( _) if self_substs. self_r . is_some ( ) => {
478
+ move self_substs
479
+ }
480
+ sty_region( _) => {
481
+ { self_r:
482
+ Some ( self . infcx ( ) . next_region_var (
483
+ self . expr . span ,
484
+ self . expr . id ) ) ,
485
+ ..self_substs}
486
+ }
487
+ }
488
+ } ;
489
+
490
+ let rcvr_ty =
491
+ transform_self_type_for_method (
492
+ self . tcx ( ) , rcvr_substs. self_r ,
493
+ self_ty, self_decl) ;
494
+
495
+ ( rcvr_ty, rcvr_substs)
496
+ }
497
+
449
498
// ______________________________________________________________________
450
499
// Candidate selection (see comment at start of file)
451
500
0 commit comments