@@ -176,13 +176,7 @@ pub struct LookupContext<'self> {
176
176
pub struct Candidate {
177
177
rcvr_ty : ty:: t ,
178
178
rcvr_substs : ty:: substs ,
179
- explicit_self : ast:: self_ty_ ,
180
-
181
- // FIXME #3446---these two fields should be easily derived from
182
- // origin, yet are not
183
- num_method_tps : uint ,
184
- self_mode : ast:: rmode ,
185
-
179
+ method_ty : @ty:: method ,
186
180
origin : method_origin ,
187
181
}
188
182
@@ -474,7 +468,7 @@ pub impl<'self> LookupContext<'self> {
474
468
}
475
469
}
476
470
} ;
477
- let method = & trait_methods[ pos] ;
471
+ let method = trait_methods[ pos] ;
478
472
479
473
let ( rcvr_ty, rcvr_substs) =
480
474
self . create_rcvr_ty_and_substs_for_method (
@@ -486,9 +480,7 @@ pub impl<'self> LookupContext<'self> {
486
480
let cand = Candidate {
487
481
rcvr_ty : rcvr_ty,
488
482
rcvr_substs : rcvr_substs,
489
- explicit_self : method. self_ty ,
490
- num_method_tps : method. tps . len ( ) ,
491
- self_mode : get_mode_from_self_type ( method. self_ty ) ,
483
+ method_ty : method,
492
484
origin : method_param (
493
485
method_param {
494
486
trait_id : init_trait_id,
@@ -520,7 +512,7 @@ pub impl<'self> LookupContext<'self> {
520
512
Some ( i) => i,
521
513
None => { return ; } // no method with the right name
522
514
} ;
523
- let method = & ms[ index] ;
515
+ let method = ms[ index] ;
524
516
525
517
/* FIXME(#3157) we should transform the vstore in accordance
526
518
with the self type
@@ -554,9 +546,7 @@ pub impl<'self> LookupContext<'self> {
554
546
self . inherent_candidates . push ( Candidate {
555
547
rcvr_ty : rcvr_ty,
556
548
rcvr_substs : rcvr_substs,
557
- explicit_self : method. self_ty ,
558
- num_method_tps : method. tps . len ( ) ,
559
- self_mode : get_mode_from_self_type ( method. self_ty ) ,
549
+ method_ty : method,
560
550
origin : method_trait ( did, index, store)
561
551
} ) ;
562
552
}
@@ -565,63 +555,65 @@ pub impl<'self> LookupContext<'self> {
565
555
self_ty : ty:: t ,
566
556
did : def_id ,
567
557
substs : & ty:: substs ) {
558
+ struct MethodInfo {
559
+ method_ty : @ty:: method ,
560
+ trait_def_id : ast:: def_id ,
561
+ index : uint
562
+ }
563
+
568
564
let tcx = self . tcx ( ) ;
569
565
// First, try self methods
570
- let mut method = None ;
566
+ let mut method_info : Option < MethodInfo > = None ;
571
567
let methods = ty:: trait_methods ( tcx, did) ;
572
- let mut index = None ;
573
- let mut trait_did = None ;
574
568
match vec:: position ( * methods, |m| m. ident == self . m_name ) {
575
569
Some ( i) => {
576
- index = Some ( i) ;
577
- trait_did = Some ( did) ;
578
- method = Some ( ( methods[ i] . self_ty , methods[ i] . tps . len ( ) ) ) ;
570
+ method_info = Some ( MethodInfo {
571
+ method_ty : methods[ i] ,
572
+ index : i,
573
+ trait_def_id : did
574
+ } ) ;
579
575
}
580
576
None => ( )
581
577
}
582
578
// No method found yet? Check each supertrait
583
- if method . is_none ( ) {
579
+ if method_info . is_none ( ) {
584
580
for ty:: trait_supertraits( tcx, did) . each( ) |trait_ref| {
585
581
let supertrait_methods =
586
582
ty:: trait_methods ( tcx, trait_ref. def_id ) ;
587
583
match vec:: position ( * supertrait_methods,
588
584
|m| m. ident == self . m_name ) {
589
585
Some ( i) => {
590
- index = Some ( i) ;
591
- trait_did = Some ( trait_ref. def_id ) ;
592
- method = Some ( ( supertrait_methods[ i] . self_ty ,
593
- supertrait_methods[ i] . tps . len ( ) ) ) ;
586
+ method_info = Some ( MethodInfo {
587
+ method_ty : supertrait_methods[ i] ,
588
+ index : i,
589
+ trait_def_id : trait_ref. def_id
590
+ } ) ;
594
591
break ;
595
592
}
596
593
None => ( )
597
594
}
598
595
}
599
596
}
600
- match ( method, index, trait_did) {
601
- ( Some ( ( method_self_ty, method_num_tps) ) ,
602
- Some ( index) , Some ( trait_did) ) => {
603
-
597
+ match method_info {
598
+ Some ( ref info) => {
604
599
// We've found a method -- return it
605
- let rcvr_substs = substs { self_ty : Some ( self_ty) ,
600
+ let rcvr_substs = substs { self_ty : Some ( self_ty) ,
606
601
..copy * substs } ;
607
602
let ( rcvr_ty, rcvr_substs) =
608
603
self . create_rcvr_ty_and_substs_for_method (
609
- method_self_ty ,
604
+ info . method_ty . self_ty ,
610
605
self_ty,
611
606
rcvr_substs,
612
607
TransformTypeNormally ) ;
613
- let origin = if trait_did == did {
614
- method_self ( trait_did, index)
615
- }
616
- else {
617
- method_super ( trait_did, index)
608
+ let origin = if did == info. trait_def_id {
609
+ method_self ( info. trait_def_id , info. index )
610
+ } else {
611
+ method_super ( info. trait_def_id , info. index )
618
612
} ;
619
613
self . inherent_candidates . push ( Candidate {
620
614
rcvr_ty : rcvr_ty,
621
615
rcvr_substs : rcvr_substs,
622
- explicit_self : method_self_ty,
623
- num_method_tps : method_num_tps,
624
- self_mode : get_mode_from_self_type ( method_self_ty) ,
616
+ method_ty : info. method_ty ,
625
617
origin : origin
626
618
} ) ;
627
619
}
@@ -653,7 +645,7 @@ pub impl<'self> LookupContext<'self> {
653
645
}
654
646
} ;
655
647
656
- let method = & impl_info. methods [ idx] ;
648
+ let method = ty :: method ( self . tcx ( ) , impl_info. methods [ idx] . did ) ;
657
649
658
650
// determine the `self` of the impl with fresh
659
651
// variables for each parameter:
@@ -669,18 +661,16 @@ pub impl<'self> LookupContext<'self> {
669
661
670
662
let ( impl_ty, impl_substs) =
671
663
self . create_rcvr_ty_and_substs_for_method (
672
- method. self_type ,
664
+ method. self_ty ,
673
665
impl_ty,
674
666
impl_substs,
675
667
TransformTypeNormally ) ;
676
668
677
669
candidates. push ( Candidate {
678
670
rcvr_ty : impl_ty,
679
671
rcvr_substs : impl_substs,
680
- explicit_self : method. self_type ,
681
- num_method_tps : method. n_tps ,
682
- self_mode : get_mode_from_self_type ( method. self_type ) ,
683
- origin : method_static ( method. did )
672
+ method_ty : method,
673
+ origin : method_static ( method. def_id )
684
674
} ) ;
685
675
}
686
676
@@ -701,6 +691,9 @@ pub impl<'self> LookupContext<'self> {
701
691
debug ! ( "(pushing candidates from provided methods) adding \
702
692
candidate") ;
703
693
694
+ let method = ty:: method ( self . tcx ( ) ,
695
+ provided_method_info. method_info . did ) ;
696
+
704
697
// XXX: Needs to support generics.
705
698
let dummy_substs = substs {
706
699
self_r : None ,
@@ -709,18 +702,15 @@ pub impl<'self> LookupContext<'self> {
709
702
} ;
710
703
let ( impl_ty, impl_substs) =
711
704
self . create_rcvr_ty_and_substs_for_method (
712
- provided_method_info . method_info . self_type ,
705
+ method . self_ty ,
713
706
self_ty,
714
707
dummy_substs,
715
708
TransformTypeNormally ) ;
716
709
717
710
candidates. push ( Candidate {
718
711
rcvr_ty : impl_ty,
719
712
rcvr_substs : impl_substs,
720
- explicit_self : provided_method_info. method_info . self_type ,
721
- num_method_tps : provided_method_info. method_info . n_tps ,
722
- self_mode : get_mode_from_self_type (
723
- provided_method_info. method_info . self_type ) ,
713
+ method_ty : method,
724
714
origin : method_static ( provided_method_info. method_info . did )
725
715
} ) ;
726
716
}
@@ -1126,20 +1116,21 @@ pub impl<'self> LookupContext<'self> {
1126
1116
// If they were not explicitly supplied, just construct fresh
1127
1117
// type variables.
1128
1118
let num_supplied_tps = self . supplied_tps . len ( ) ;
1119
+ let num_method_tps = candidate. method_ty . tps . len ( ) ;
1129
1120
let m_substs = {
1130
1121
if num_supplied_tps == 0 u {
1131
- self . fcx . infcx ( ) . next_ty_vars ( candidate . num_method_tps )
1132
- } else if candidate . num_method_tps == 0 u {
1122
+ self . fcx . infcx ( ) . next_ty_vars ( num_method_tps)
1123
+ } else if num_method_tps == 0 u {
1133
1124
tcx. sess . span_err (
1134
1125
self . expr . span ,
1135
1126
~"this method does not take type parameters") ;
1136
- self . fcx . infcx ( ) . next_ty_vars ( candidate . num_method_tps )
1137
- } else if num_supplied_tps != candidate . num_method_tps {
1127
+ self . fcx . infcx ( ) . next_ty_vars ( num_method_tps)
1128
+ } else if num_supplied_tps != num_method_tps {
1138
1129
tcx. sess . span_err (
1139
1130
self . expr . span ,
1140
1131
~"incorrect number of type \
1141
1132
parameters given for this method") ;
1142
- self . fcx. infcx( ) . next_ty_vars( candidate . num_method_tps)
1133
+ self . fcx. infcx( ) . next_ty_vars( num_method_tps)
1143
1134
} else {
1144
1135
self . supplied_tps. to_vec( )
1145
1136
}
@@ -1178,14 +1169,16 @@ pub impl<'self> LookupContext<'self> {
1178
1169
let fty = ty:: mk_bare_fn( tcx, ty:: BareFnTy { sig: fn_sig, ..bare_fn_ty} ) ;
1179
1170
debug ! ( "after replacing bound regions, fty=%s" , self . ty_to_str( fty) ) ;
1180
1171
1172
+ let self_mode = get_mode_from_self_type ( candidate. method_ty . self_ty ) ;
1173
+
1181
1174
self . fcx . write_ty ( self . callee_id , fty) ;
1182
1175
self . fcx . write_substs ( self . callee_id , all_substs) ;
1183
1176
method_map_entry {
1184
1177
self_arg : arg {
1185
- mode : ast:: expl ( candidate . self_mode ) ,
1178
+ mode : ast:: expl ( self_mode) ,
1186
1179
ty : candidate. rcvr_ty ,
1187
1180
} ,
1188
- explicit_self : candidate. explicit_self ,
1181
+ explicit_self : candidate. method_ty . self_ty ,
1189
1182
origin : candidate. origin ,
1190
1183
}
1191
1184
}
@@ -1217,7 +1210,7 @@ pub impl<'self> LookupContext<'self> {
1217
1210
self -type through a boxed trait") ;
1218
1211
}
1219
1212
1220
- if candidate. num_method_tps > 0 {
1213
+ if candidate. method_ty . tps . len ( ) > 0 {
1221
1214
self . tcx ( ) . sess . span_err (
1222
1215
self . expr . span ,
1223
1216
~"cannot call a generic method through a boxed trait ") ;
@@ -1334,10 +1327,9 @@ pub impl<'self> LookupContext<'self> {
1334
1327
}
1335
1328
1336
1329
fn cand_to_str ( & self , cand : & Candidate ) -> ~str {
1337
- fmt ! ( "Candidate(rcvr_ty=%s, rcvr_substs=%s, self_mode=%?, origin=%?)" ,
1330
+ fmt ! ( "Candidate(rcvr_ty=%s, rcvr_substs=%s, origin=%?)" ,
1338
1331
self . ty_to_str( cand. rcvr_ty) ,
1339
1332
ty:: substs_to_str( self . tcx( ) , & cand. rcvr_substs) ,
1340
- cand. self_mode,
1341
1333
cand. origin)
1342
1334
}
1343
1335
0 commit comments