@@ -82,6 +82,7 @@ obtained the type `Foo`, we would never match this method.
82
82
83
83
use middle:: subst;
84
84
use middle:: subst:: Subst ;
85
+ use middle:: traits;
85
86
use middle:: ty:: * ;
86
87
use middle:: ty;
87
88
use middle:: typeck:: astconv:: AstConv ;
@@ -91,7 +92,6 @@ use middle::typeck::infer;
91
92
use middle:: typeck:: MethodCallee ;
92
93
use middle:: typeck:: { MethodOrigin , MethodParam } ;
93
94
use middle:: typeck:: { MethodStatic , MethodStaticUnboxedClosure , MethodObject } ;
94
- use middle:: typeck:: { param_index} ;
95
95
use middle:: typeck:: check:: regionmanip:: replace_late_bound_regions_in_fn_sig;
96
96
use middle:: typeck:: TypeAndSubsts ;
97
97
use util:: common:: indenter;
@@ -538,14 +538,12 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
538
538
return
539
539
}
540
540
541
- let vcx = self . fcx . vtable_context ( ) ;
542
-
543
541
// Get the tupled type of the arguments.
544
542
let arguments_type = * closure_function_type. sig . inputs . get ( 0 ) ;
545
543
let return_type = closure_function_type. sig . output ;
546
544
547
545
let closure_region =
548
- vcx . infcx . next_region_var ( infer:: MiscVariable ( self . span ) ) ;
546
+ self . fcx . infcx ( ) . next_region_var ( infer:: MiscVariable ( self . span ) ) ;
549
547
let unboxed_closure_type = ty:: mk_unboxed_closure ( self . tcx ( ) ,
550
548
closure_did,
551
549
closure_region) ;
@@ -555,7 +553,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
555
553
rcvr_substs : subst:: Substs :: new_trait (
556
554
vec ! [ arguments_type, return_type] ,
557
555
vec ! [ ] ,
558
- * vcx . infcx . next_ty_vars ( 1 ) . get ( 0 ) ) ,
556
+ * self . fcx . infcx ( ) . next_ty_vars ( 1 ) . get ( 0 ) ) ,
559
557
method_ty : method,
560
558
origin : MethodStaticUnboxedClosure ( closure_did) ,
561
559
} ) ;
@@ -618,7 +616,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
618
616
619
617
self . push_inherent_candidates_from_bounds_inner (
620
618
& [ trait_ref. clone ( ) ] ,
621
- |_this, new_trait_ref, m, method_num, _bound_num | {
619
+ |_this, new_trait_ref, m, method_num| {
622
620
let vtable_index =
623
621
get_method_index ( tcx, & * new_trait_ref,
624
622
trait_ref. clone ( ) , method_num) ;
@@ -633,7 +631,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
633
631
rcvr_substs : new_trait_ref. substs . clone ( ) ,
634
632
method_ty : Rc :: new ( m) ,
635
633
origin : MethodObject ( MethodObject {
636
- trait_id : new_trait_ref. def_id ,
634
+ trait_ref : new_trait_ref,
637
635
object_trait_id : did,
638
636
method_num : method_num,
639
637
real_index : vtable_index
@@ -652,22 +650,20 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
652
650
rcvr_ty,
653
651
param_ty. space ,
654
652
param_ty. idx ,
655
- restrict_to,
656
- param_index { space : param_ty. space , index : param_ty. idx } ) ;
653
+ restrict_to) ;
657
654
}
658
655
659
656
660
657
fn push_inherent_candidates_from_bounds ( & mut self ,
661
658
self_ty : ty:: t ,
662
659
space : subst:: ParamSpace ,
663
660
index : uint ,
664
- restrict_to : Option < DefId > ,
665
- param : param_index ) {
661
+ restrict_to : Option < DefId > ) {
666
662
let bounds =
667
663
self . fcx . inh . param_env . bounds . get ( space, index) . trait_bounds
668
664
. as_slice ( ) ;
669
665
self . push_inherent_candidates_from_bounds_inner ( bounds,
670
- |this, trait_ref, m, method_num, bound_num | {
666
+ |this, trait_ref, m, method_num| {
671
667
match restrict_to {
672
668
Some ( trait_did) => {
673
669
if trait_did != trait_ref. def_id {
@@ -701,10 +697,8 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
701
697
rcvr_substs : trait_ref. substs . clone ( ) ,
702
698
method_ty : m,
703
699
origin : MethodParam ( MethodParam {
704
- trait_id : trait_ref. def_id ,
700
+ trait_ref : trait_ref,
705
701
method_num : method_num,
706
- param_num : param,
707
- bound_num : bound_num,
708
702
} )
709
703
} )
710
704
} )
@@ -718,15 +712,16 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
718
712
mk_cand: |this: & mut LookupContext ,
719
713
tr : Rc < TraitRef > ,
720
714
m : Rc < ty:: Method > ,
721
- method_num : uint ,
722
- bound_num : uint |
723
- -> Option < Candidate > ) {
715
+ method_num : uint |
716
+ -> Option < Candidate > )
717
+ {
724
718
let tcx = self . tcx ( ) ;
725
- let mut next_bound_idx = 0 ; // count only trait bounds
726
-
727
- ty:: each_bound_trait_and_supertraits ( tcx, bounds, |bound_trait_ref| {
728
- let this_bound_idx = next_bound_idx;
729
- next_bound_idx += 1 ;
719
+ let mut cache = HashSet :: new ( ) ;
720
+ for bound_trait_ref in traits:: transitive_bounds ( tcx, bounds) {
721
+ // Already visited this trait, skip it.
722
+ if !cache. insert ( bound_trait_ref. def_id ) {
723
+ continue ;
724
+ }
730
725
731
726
let trait_items = ty:: trait_items ( tcx, bound_trait_ref. def_id ) ;
732
727
match trait_items. iter ( ) . position ( |ti| {
@@ -745,8 +740,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
745
740
match mk_cand ( self ,
746
741
bound_trait_ref,
747
742
method,
748
- pos,
749
- this_bound_idx) {
743
+ pos) {
750
744
Some ( cand) => {
751
745
debug ! ( "pushing inherent candidate for param: {}" ,
752
746
cand. repr( self . tcx( ) ) ) ;
@@ -761,8 +755,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
761
755
// check next trait or bound
762
756
}
763
757
}
764
- true
765
- } ) ;
758
+ }
766
759
}
767
760
768
761
@@ -773,7 +766,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
773
766
774
767
let impl_items = self . tcx ( ) . impl_items . borrow ( ) ;
775
768
for impl_infos in self . tcx ( ) . inherent_impls . borrow ( ) . find ( & did) . iter ( ) {
776
- for impl_did in impl_infos. borrow ( ) . iter ( ) {
769
+ for impl_did in impl_infos. iter ( ) {
777
770
let items = impl_items. get ( impl_did) ;
778
771
self . push_candidates_from_impl ( * impl_did,
779
772
items. as_slice ( ) ,
@@ -825,11 +818,10 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
825
818
// determine the `self` of the impl with fresh
826
819
// variables for each parameter:
827
820
let span = self . self_expr . map_or ( self . span , |e| e. span ) ;
828
- let vcx = self . fcx . vtable_context ( ) ;
829
821
let TypeAndSubsts {
830
822
substs : impl_substs,
831
823
ty : impl_ty
832
- } = impl_self_ty ( & vcx , span, impl_did) ;
824
+ } = impl_self_ty ( self . fcx , span, impl_did) ;
833
825
834
826
let condition = match method. explicit_self {
835
827
ByReferenceExplicitSelfCategory ( _, mt) if mt == MutMutable =>
@@ -877,7 +869,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
877
869
adjustment {:?} for {}", adjustment, self . ty_to_string( self_ty) ) ;
878
870
match adjustment {
879
871
Some ( ( self_expr_id, adj) ) => {
880
- self . fcx . write_adjustment ( self_expr_id, adj) ;
872
+ self . fcx . write_adjustment ( self_expr_id, self . span , adj) ;
881
873
}
882
874
None => { }
883
875
}
@@ -1109,7 +1101,9 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1109
1101
1110
1102
ty_err => None ,
1111
1103
1112
- ty_infer( TyVar ( _) ) => {
1104
+ ty_infer( TyVar ( _) ) |
1105
+ ty_infer( SkolemizedTy ( _) ) |
1106
+ ty_infer( SkolemizedIntTy ( _) ) => {
1113
1107
self . bug ( format ! ( "unexpected type: {}" ,
1114
1108
self . ty_to_string( self_ty) ) . as_slice ( ) ) ;
1115
1109
}
@@ -1150,6 +1144,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1150
1144
Some ( self_expr_id) => {
1151
1145
self . fcx . write_adjustment (
1152
1146
self_expr_id,
1147
+ self . span ,
1153
1148
ty:: AutoDerefRef ( ty:: AutoDerefRef {
1154
1149
autoderefs : autoderefs,
1155
1150
autoref : Some ( kind ( region, * mutbl) )
@@ -1209,7 +1204,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1209
1204
1210
1205
// return something so we don't get errors for every mutability
1211
1206
return Some ( MethodCallee {
1212
- origin : relevant_candidates. get ( 0 ) . origin ,
1207
+ origin : relevant_candidates. get ( 0 ) . origin . clone ( ) ,
1213
1208
ty : ty:: mk_err ( ) ,
1214
1209
substs : subst:: Substs :: empty ( )
1215
1210
} ) ;
@@ -1237,12 +1232,14 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1237
1232
candidate_b. repr( self . tcx( ) ) ) ;
1238
1233
match ( & candidate_a. origin , & candidate_b. origin ) {
1239
1234
( & MethodParam ( ref p1) , & MethodParam ( ref p2) ) => {
1240
- let same_trait = p1. trait_id == p2. trait_id ;
1241
- let same_method = p1. method_num == p2. method_num ;
1242
- let same_param = p1. param_num == p2. param_num ;
1243
- // The bound number may be different because
1244
- // multiple bounds may lead to the same trait
1245
- // impl
1235
+ let same_trait =
1236
+ p1. trait_ref . def_id == p2. trait_ref . def_id ;
1237
+ let same_method =
1238
+ p1. method_num == p2. method_num ;
1239
+ // it's ok to compare self-ty with `==` here because
1240
+ // they are always a TyParam
1241
+ let same_param =
1242
+ p1. trait_ref . self_ty ( ) == p2. trait_ref . self_ty ( ) ;
1246
1243
same_trait && same_method && same_param
1247
1244
}
1248
1245
_ => false
@@ -1369,13 +1366,13 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1369
1366
}
1370
1367
}
1371
1368
1372
- self . fcx . add_region_obligations_for_parameters (
1373
- self . span ,
1369
+ self . fcx . add_obligations_for_parameters (
1370
+ traits :: ObligationCause :: misc ( self . span ) ,
1374
1371
& all_substs,
1375
1372
& candidate. method_ty . generics ) ;
1376
1373
1377
1374
MethodCallee {
1378
- origin : candidate. origin ,
1375
+ origin : candidate. origin . clone ( ) ,
1379
1376
ty : fty,
1380
1377
substs : all_substs
1381
1378
}
@@ -1452,10 +1449,10 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1452
1449
MethodStaticUnboxedClosure ( _) => bad = false ,
1453
1450
// FIXME: does this properly enforce this on everything now
1454
1451
// that self has been merged in? -sully
1455
- MethodParam ( MethodParam { trait_id : trait_id , .. } ) |
1456
- MethodObject ( MethodObject { trait_id : trait_id , .. } ) => {
1452
+ MethodParam ( MethodParam { trait_ref : ref trait_ref , .. } ) |
1453
+ MethodObject ( MethodObject { trait_ref : ref trait_ref , .. } ) => {
1457
1454
bad = self . tcx ( ) . destructor_for_type . borrow ( )
1458
- . contains_key ( & trait_id ) ;
1455
+ . contains_key ( & trait_ref . def_id ) ;
1459
1456
}
1460
1457
}
1461
1458
@@ -1602,10 +1599,10 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1602
1599
self . report_static_candidate ( idx, did)
1603
1600
}
1604
1601
MethodParam ( ref mp) => {
1605
- self . report_param_candidate ( idx, ( * mp ) . trait_id )
1602
+ self . report_param_candidate ( idx, mp . trait_ref . def_id )
1606
1603
}
1607
1604
MethodObject ( ref mo) => {
1608
- self . report_trait_candidate ( idx, mo. trait_id )
1605
+ self . report_trait_candidate ( idx, mo. trait_ref . def_id )
1609
1606
}
1610
1607
}
1611
1608
}
0 commit comments