@@ -168,7 +168,7 @@ fn create_steps<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
168
168
check:: autoderef (
169
169
fcx, span, self_ty, None , NoPreference ,
170
170
|t, d| {
171
- let adjustment = consider_reborrow ( t , d) ;
171
+ let adjustment = AutoDeref ( d) ;
172
172
steps. push ( CandidateStep { self_ty : t, adjustment : adjustment } ) ;
173
173
None :: < ( ) > // keep iterating until we can't anymore
174
174
} ) ;
@@ -185,14 +185,6 @@ fn create_steps<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
185
185
}
186
186
187
187
return steps;
188
-
189
- fn consider_reborrow ( ty : Ty , d : uint ) -> PickAdjustment {
190
- // Insert a `&*` or `&mut *` if this is a reference type:
191
- match ty. sty {
192
- ty:: ty_rptr( _, ref mt) => AutoRef ( mt. mutbl , box AutoDeref ( d+1 ) ) ,
193
- _ => AutoDeref ( d) ,
194
- }
195
- }
196
188
}
197
189
198
190
impl < ' a , ' tcx > ProbeContext < ' a , ' tcx > {
@@ -626,7 +618,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
626
618
return None ;
627
619
}
628
620
629
- match self . pick_adjusted_method ( step) {
621
+ match self . pick_by_value_method ( step) {
630
622
Some ( result) => return Some ( result) ,
631
623
None => { }
632
624
}
@@ -644,11 +636,34 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
644
636
}
645
637
}
646
638
647
- fn pick_adjusted_method ( & mut self ,
639
+ fn pick_by_value_method ( & mut self ,
648
640
step : & CandidateStep < ' tcx > )
649
641
-> Option < PickResult < ' tcx > >
650
642
{
651
- self . pick_method ( step. self_ty ) . map ( |r| self . adjust ( r, step. adjustment . clone ( ) ) )
643
+ /*!
644
+ * For each type `T` in the step list, this attempts to find a
645
+ * method where the (transformed) self type is exactly `T`. We
646
+ * do however do one transformation on the adjustment: if we
647
+ * are passing a region pointer in, we will potentially
648
+ * *reborrow* it to a shorter lifetime. This allows us to
649
+ * transparently pass `&mut` pointers, in particular, without
650
+ * consuming them for their entire lifetime.
651
+ */
652
+
653
+ let adjustment = match step. adjustment {
654
+ AutoDeref ( d) => consider_reborrow ( step. self_ty , d) ,
655
+ AutoUnsizeLength ( ..) | AutoRef ( ..) => step. adjustment . clone ( ) ,
656
+ } ;
657
+
658
+ return self . pick_method ( step. self_ty ) . map ( |r| self . adjust ( r, adjustment. clone ( ) ) ) ;
659
+
660
+ fn consider_reborrow ( ty : Ty , d : uint ) -> PickAdjustment {
661
+ // Insert a `&*` or `&mut *` if this is a reference type:
662
+ match ty. sty {
663
+ ty:: ty_rptr( _, ref mt) => AutoRef ( mt. mutbl , box AutoDeref ( d+1 ) ) ,
664
+ _ => AutoDeref ( d) ,
665
+ }
666
+ }
652
667
}
653
668
654
669
fn pick_autorefd_method ( & mut self ,
0 commit comments