@@ -77,16 +77,20 @@ class lookup {
77
77
// loop for impls in scope. Note: I don't love these
78
78
// semantics, but that's what we had so I am preserving
79
79
// it.
80
- if self . candidates . len ( ) > 0 u {
81
- break ;
82
- }
80
+ if self . candidates . len ( ) > 0 u { break ; }
81
+
82
+ // now look for impls in scope, but don't look for impls that
83
+ // would require doing an implicit borrow of the lhs.
84
+ self . add_candidates_from_scope ( false ) ;
83
85
84
- self . add_candidates_from_scope ( ) ;
86
+ // if we found anything, stop before trying borrows
87
+ if self . candidates . len ( ) > 0 u { break ; }
88
+
89
+ // now look for impls in scope that might require a borrow
90
+ self . add_candidates_from_scope ( true ) ;
85
91
86
92
// if we found anything, stop before attempting auto-deref.
87
- if self . candidates . len ( ) > 0 u {
88
- break ;
89
- }
93
+ if self . candidates . len ( ) > 0 u { break ; }
90
94
91
95
// check whether we can autoderef and if so loop around again.
92
96
alt ty:: deref ( self . tcx ( ) , self . self_ty , false ) {
@@ -290,7 +294,7 @@ class lookup {
290
294
*/
291
295
}
292
296
293
- fn add_candidates_from_scope ( ) {
297
+ fn add_candidates_from_scope ( use_assignability : bool ) {
294
298
let impls_vecs = self . fcx . ccx . impl_map . get ( self . expr . id ) ;
295
299
let mut added_any = false ;
296
300
@@ -306,13 +310,18 @@ class lookup {
306
310
let { substs: impl_substs , ty: impl_ty} =
307
311
impl_self_ty ( self . fcx , im. did ) ;
308
312
309
- // if we can assign the caller to the callee, that's a
310
- // potential match. Collect those in the vector.
311
- let can_assign = self . fcx . can_mk_assignty (
312
- self . self_expr , self . borrow_scope ,
313
- self . self_ty , impl_ty) ;
314
- #debug[ "can_assign = %?" , can_assign] ;
315
- alt can_assign {
313
+ // Depending on our argument, we find potential
314
+ // matches either by checking subtypability or
315
+ // type assignability. Collect the matches.
316
+ let matches = if use_assignability {
317
+ self . fcx . can_mk_assignty (
318
+ self . self_expr , self . borrow_scope ,
319
+ self . self_ty , impl_ty)
320
+ } else {
321
+ self . fcx . can_mk_subty ( self . self_ty , impl_ty)
322
+ } ;
323
+ #debug[ "matches = %?" , matches] ;
324
+ alt matches {
316
325
result : : err ( _) { /* keep looking */ }
317
326
result:: ok ( _) {
318
327
if !self . candidate_impls . contains_key ( im. did ) {
0 commit comments