@@ -48,11 +48,12 @@ candidates in the same way.
48
48
49
49
If find no matching candidate at all, we proceed to auto-deref the
50
50
receiver type and search again. We keep doing that until we cannot
51
- auto-deref any longer. At that point, we will attempt an auto-ref.
52
- If THAT fails, method lookup fails altogether. Autoref itself comes
53
- in two varieties, autoslice and autoptr. The former converts `~[]` to
54
- `&[]` and the latter converts any type `T` to `&mut T`, `&const T`, or
55
- `&T`.
51
+ auto-deref any longer. At each step, we also check for candidates
52
+ based on "autoptr", which if the current type is `T`, checks for `&mut
53
+ T`, `&const T`, and `&T` receivers. Finally, at the very end, we will
54
+ also try autoslice, which converts `~[]` to `&[]` (there is no point
55
+ at trying autoslice earlier, because no autoderefable type is also
56
+ sliceable).
56
57
57
58
## Why two phases?
58
59
@@ -159,22 +160,9 @@ impl LookupContext {
159
160
None => { }
160
161
}
161
162
162
- // some special logic around newtypes:
163
- match ty:: get ( self_ty) . sty {
164
- ty_enum( * ) => {
165
- // Note: in general, we prefer not to auto-ref a
166
- // partially autoderef'd type, because it
167
- // seems... crazy. But we have to be careful
168
- // around newtype enums. They can be further
169
- // deref'd, but they may also have intrinsic
170
- // methods hanging off of them with interior type.
171
- match self . search_for_any_autorefd_method ( self_ty,
172
- autoderefs) {
173
- Some ( move mme) => { return Some ( mme) ; }
174
- None => { }
175
- }
176
- }
177
- _ => { }
163
+ match self . search_for_autoptrd_method ( self_ty, autoderefs) {
164
+ Some ( move mme) => { return Some ( move mme) ; }
165
+ None => { }
178
166
}
179
167
180
168
match self . deref ( self_ty, & enum_dids) {
@@ -186,7 +174,7 @@ impl LookupContext {
186
174
}
187
175
}
188
176
189
- self . search_for_any_autorefd_method ( self_ty, autoderefs)
177
+ self . search_for_autosliced_method ( self_ty, autoderefs)
190
178
}
191
179
192
180
fn deref ( ty : ty:: t , enum_dids : & DVec < ast:: def_id > ) -> Option < ty:: t > {
@@ -516,30 +504,6 @@ impl LookupContext {
516
504
}
517
505
}
518
506
519
- fn search_for_any_autorefd_method (
520
- & self ,
521
- self_ty : ty:: t ,
522
- autoderefs : uint )
523
- -> Option < method_map_entry >
524
- {
525
- /*!
526
- *
527
- * Attempts both auto-slice and auto-ptr, as appropriate.
528
- */
529
-
530
- match self . search_for_autosliced_method ( self_ty, autoderefs) {
531
- Some ( move mme) => { return Some ( move mme) ; }
532
- None => { }
533
- }
534
-
535
- match self . search_for_autoptrd_method ( self_ty, autoderefs) {
536
- Some ( move mme) => { return Some ( move mme) ; }
537
- None => { }
538
- }
539
-
540
- return None ;
541
- }
542
-
543
507
fn search_for_autosliced_method (
544
508
& self ,
545
509
self_ty : ty:: t ,
@@ -594,13 +558,7 @@ impl LookupContext {
594
558
595
559
let tcx = self . tcx ( ) ;
596
560
match ty:: get ( self_ty) . sty {
597
- ty_box( * ) | ty_uniq( * ) | ty_rptr( * ) => {
598
- // we should be fully autoderef'd
599
- self . bug ( fmt ! ( "Receiver type %s should be fully \
600
- autoderef'd by this point",
601
- self . ty_to_str( self_ty) ) ) ;
602
- }
603
-
561
+ ty_box( * ) | ty_uniq( * ) | ty_rptr( * ) |
604
562
ty_infer( IntVar ( _) ) | // FIXME(#3211)---should be resolved
605
563
ty_self | ty_param( * ) | ty_nil | ty_bot | ty_bool |
606
564
ty_int( * ) | ty_uint( * ) |
0 commit comments