@@ -416,7 +416,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
416
416
kind : kind,
417
417
} ;
418
418
419
- debug ! ( "unadjusted-expr={:?} applying adjustments={:?}" ,
419
+ debug ! ( "make_mirror: unadjusted-expr={:?} applying adjustments={:?}" ,
420
420
expr, cx. tcx. tables. borrow( ) . adjustments. get( & self . id) ) ;
421
421
422
422
// Now apply adjustments, if any.
@@ -459,10 +459,38 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
459
459
self . span ,
460
460
i,
461
461
|mc| cx. tcx . tables . borrow ( ) . method_map . get ( & mc) . map ( |m| m. ty ) ) ;
462
- let kind = if cx. tcx . is_overloaded_autoderef ( self . id , i) {
463
- overloaded_lvalue ( cx, self , ty:: MethodCall :: autoderef ( self . id , i) ,
464
- PassArgs :: ByValue , expr. to_ref ( ) , vec ! [ ] )
462
+ debug ! ( "make_mirror: autoderef #{}, adjusted_ty={:?}" , i, adjusted_ty) ;
463
+ let method_key = ty:: MethodCall :: autoderef ( self . id , i) ;
464
+ let meth_ty =
465
+ cx. tcx . tables . borrow ( ) . method_map . get ( & method_key) . map ( |m| m. ty ) ;
466
+ let kind = if let Some ( meth_ty) = meth_ty {
467
+ debug ! ( "make_mirror: overloaded autoderef (meth_ty={:?})" , meth_ty) ;
468
+
469
+ let ref_ty = cx. tcx . no_late_bound_regions ( & meth_ty. fn_ret ( ) ) ;
470
+ let ( region, mutbl) = match ref_ty {
471
+ Some ( ty:: FnConverging ( & ty:: TyS {
472
+ sty : ty:: TyRef ( region, mt) , ..
473
+ } ) ) => ( region, mt. mutbl ) ,
474
+ _ => cx. tcx . sess . span_bug (
475
+ expr. span , "autoderef returned bad type" )
476
+ } ;
477
+
478
+ expr = Expr {
479
+ temp_lifetime : temp_lifetime,
480
+ ty : cx. tcx . mk_ref (
481
+ region, ty:: TypeAndMut { ty : expr. ty , mutbl : mutbl } ) ,
482
+ span : expr. span ,
483
+ kind : ExprKind :: Borrow {
484
+ region : * region,
485
+ borrow_kind : to_borrow_kind ( mutbl) ,
486
+ arg : expr. to_ref ( )
487
+ }
488
+ } ;
489
+
490
+ overloaded_lvalue ( cx, self , method_key,
491
+ PassArgs :: ByRef , expr. to_ref ( ) , vec ! [ ] )
465
492
} else {
493
+ debug ! ( "make_mirror: built-in autoderef" ) ;
466
494
ExprKind :: Deref { arg : expr. to_ref ( ) }
467
495
} ;
468
496
expr = Expr {
0 commit comments