@@ -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;
@@ -537,14 +537,12 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
537
537
return
538
538
}
539
539
540
- let vcx = self . fcx . vtable_context ( ) ;
541
-
542
540
// Get the tupled type of the arguments.
543
541
let arguments_type = * closure_function_type. sig . inputs . get ( 0 ) ;
544
542
let return_type = closure_function_type. sig . output ;
545
543
546
544
let closure_region =
547
- vcx . infcx . next_region_var ( infer:: MiscVariable ( self . span ) ) ;
545
+ self . fcx . infcx ( ) . next_region_var ( infer:: MiscVariable ( self . span ) ) ;
548
546
let unboxed_closure_type = ty:: mk_unboxed_closure ( self . tcx ( ) ,
549
547
closure_did,
550
548
closure_region) ;
@@ -554,7 +552,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
554
552
rcvr_substs : subst:: Substs :: new_trait (
555
553
vec ! [ arguments_type, return_type] ,
556
554
vec ! [ ] ,
557
- * vcx . infcx . next_ty_vars ( 1 ) . get ( 0 ) ) ,
555
+ * self . fcx . infcx ( ) . next_ty_vars ( 1 ) . get ( 0 ) ) ,
558
556
method_ty : method,
559
557
origin : MethodStaticUnboxedClosure ( closure_did) ,
560
558
} ) ;
@@ -617,7 +615,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
617
615
618
616
self . push_inherent_candidates_from_bounds_inner (
619
617
& [ trait_ref. clone ( ) ] ,
620
- |_this, new_trait_ref, m, method_num, _bound_num | {
618
+ |_this, new_trait_ref, m, method_num| {
621
619
let vtable_index =
622
620
get_method_index ( tcx, & * new_trait_ref,
623
621
trait_ref. clone ( ) , method_num) ;
@@ -632,7 +630,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
632
630
rcvr_substs : new_trait_ref. substs . clone ( ) ,
633
631
method_ty : Rc :: new ( m) ,
634
632
origin : MethodObject ( MethodObject {
635
- trait_id : new_trait_ref. def_id ,
633
+ trait_ref : new_trait_ref,
636
634
object_trait_id : did,
637
635
method_num : method_num,
638
636
real_index : vtable_index
@@ -651,22 +649,20 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
651
649
rcvr_ty,
652
650
param_ty. space ,
653
651
param_ty. idx ,
654
- restrict_to,
655
- param_index { space : param_ty. space , index : param_ty. idx } ) ;
652
+ restrict_to) ;
656
653
}
657
654
658
655
659
656
fn push_inherent_candidates_from_bounds ( & mut self ,
660
657
self_ty : ty:: t ,
661
658
space : subst:: ParamSpace ,
662
659
index : uint ,
663
- restrict_to : Option < DefId > ,
664
- param : param_index ) {
660
+ restrict_to : Option < DefId > ) {
665
661
let bounds =
666
662
self . fcx . inh . param_env . bounds . get ( space, index) . trait_bounds
667
663
. as_slice ( ) ;
668
664
self . push_inherent_candidates_from_bounds_inner ( bounds,
669
- |this, trait_ref, m, method_num, bound_num | {
665
+ |this, trait_ref, m, method_num| {
670
666
match restrict_to {
671
667
Some ( trait_did) => {
672
668
if trait_did != trait_ref. def_id {
@@ -692,10 +688,8 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
692
688
rcvr_substs : trait_ref. substs . clone ( ) ,
693
689
method_ty : m,
694
690
origin : MethodParam ( MethodParam {
695
- trait_id : trait_ref. def_id ,
691
+ trait_ref : trait_ref,
696
692
method_num : method_num,
697
- param_num : param,
698
- bound_num : bound_num,
699
693
} )
700
694
} )
701
695
} )
@@ -709,15 +703,16 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
709
703
mk_cand: |this: & mut LookupContext ,
710
704
tr : Rc < TraitRef > ,
711
705
m : Rc < ty:: Method > ,
712
- method_num : uint ,
713
- bound_num : uint |
714
- -> Option < Candidate > ) {
706
+ method_num : uint |
707
+ -> Option < Candidate > )
708
+ {
715
709
let tcx = self . tcx ( ) ;
716
- let mut next_bound_idx = 0 ; // count only trait bounds
717
-
718
- ty:: each_bound_trait_and_supertraits ( tcx, bounds, |bound_trait_ref| {
719
- let this_bound_idx = next_bound_idx;
720
- next_bound_idx += 1 ;
710
+ let mut cache = HashSet :: new ( ) ;
711
+ for bound_trait_ref in traits:: transitive_bounds ( tcx, bounds) {
712
+ // Already visited this trait, skip it.
713
+ if !cache. insert ( bound_trait_ref. def_id ) {
714
+ continue ;
715
+ }
721
716
722
717
let trait_items = ty:: trait_items ( tcx, bound_trait_ref. def_id ) ;
723
718
match trait_items. iter ( ) . position ( |ti| {
@@ -736,8 +731,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
736
731
match mk_cand ( self ,
737
732
bound_trait_ref,
738
733
method,
739
- pos,
740
- this_bound_idx) {
734
+ pos) {
741
735
Some ( cand) => {
742
736
debug ! ( "pushing inherent candidate for param: {}" ,
743
737
cand. repr( self . tcx( ) ) ) ;
@@ -752,8 +746,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
752
746
// check next trait or bound
753
747
}
754
748
}
755
- true
756
- } ) ;
749
+ }
757
750
}
758
751
759
752
@@ -764,7 +757,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
764
757
765
758
let impl_items = self . tcx ( ) . impl_items . borrow ( ) ;
766
759
for impl_infos in self . tcx ( ) . inherent_impls . borrow ( ) . find ( & did) . iter ( ) {
767
- for impl_did in impl_infos. borrow ( ) . iter ( ) {
760
+ for impl_did in impl_infos. iter ( ) {
768
761
let items = impl_items. get ( impl_did) ;
769
762
self . push_candidates_from_impl ( * impl_did,
770
763
items. as_slice ( ) ,
@@ -816,11 +809,10 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
816
809
// determine the `self` of the impl with fresh
817
810
// variables for each parameter:
818
811
let span = self . self_expr . map_or ( self . span , |e| e. span ) ;
819
- let vcx = self . fcx . vtable_context ( ) ;
820
812
let TypeAndSubsts {
821
813
substs : impl_substs,
822
814
ty : impl_ty
823
- } = impl_self_ty ( & vcx , span, impl_did) ;
815
+ } = impl_self_ty ( self . fcx , span, impl_did) ;
824
816
825
817
let candidates = if is_extension {
826
818
& mut self . extension_candidates
@@ -861,7 +853,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
861
853
adjustment {:?} for {}", adjustment, self . ty_to_string( self_ty) ) ;
862
854
match adjustment {
863
855
Some ( ( self_expr_id, adj) ) => {
864
- self . fcx . write_adjustment ( self_expr_id, adj) ;
856
+ self . fcx . write_adjustment ( self_expr_id, self . span , adj) ;
865
857
}
866
858
None => { }
867
859
}
@@ -1093,7 +1085,9 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1093
1085
1094
1086
ty_err => None ,
1095
1087
1096
- ty_infer( TyVar ( _) ) => {
1088
+ ty_infer( TyVar ( _) ) |
1089
+ ty_infer( SkolemizedTy ( _) ) |
1090
+ ty_infer( SkolemizedIntTy ( _) ) => {
1097
1091
self . bug ( format ! ( "unexpected type: {}" ,
1098
1092
self . ty_to_string( self_ty) ) . as_slice ( ) ) ;
1099
1093
}
@@ -1134,6 +1128,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1134
1128
Some ( self_expr_id) => {
1135
1129
self . fcx . write_adjustment (
1136
1130
self_expr_id,
1131
+ self . span ,
1137
1132
ty:: AutoDerefRef ( ty:: AutoDerefRef {
1138
1133
autoderefs : autoderefs,
1139
1134
autoref : Some ( kind ( region, * mutbl) )
@@ -1193,7 +1188,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1193
1188
1194
1189
// return something so we don't get errors for every mutability
1195
1190
return Some ( MethodCallee {
1196
- origin : relevant_candidates. get ( 0 ) . origin ,
1191
+ origin : relevant_candidates. get ( 0 ) . origin . clone ( ) ,
1197
1192
ty : ty:: mk_err ( ) ,
1198
1193
substs : subst:: Substs :: empty ( )
1199
1194
} ) ;
@@ -1221,12 +1216,14 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1221
1216
candidate_b. repr( self . tcx( ) ) ) ;
1222
1217
match ( & candidate_a. origin , & candidate_b. origin ) {
1223
1218
( & MethodParam ( ref p1) , & MethodParam ( ref p2) ) => {
1224
- let same_trait = p1. trait_id == p2. trait_id ;
1225
- let same_method = p1. method_num == p2. method_num ;
1226
- let same_param = p1. param_num == p2. param_num ;
1227
- // The bound number may be different because
1228
- // multiple bounds may lead to the same trait
1229
- // impl
1219
+ let same_trait =
1220
+ p1. trait_ref . def_id == p2. trait_ref . def_id ;
1221
+ let same_method =
1222
+ p1. method_num == p2. method_num ;
1223
+ // it's ok to compare self-ty with `==` here because
1224
+ // they are always a TyParam
1225
+ let same_param =
1226
+ p1. trait_ref . self_ty ( ) == p2. trait_ref . self_ty ( ) ;
1230
1227
same_trait && same_method && same_param
1231
1228
}
1232
1229
_ => false
@@ -1353,13 +1350,13 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1353
1350
}
1354
1351
}
1355
1352
1356
- self . fcx . add_region_obligations_for_parameters (
1357
- self . span ,
1353
+ self . fcx . add_obligations_for_parameters (
1354
+ traits :: ObligationCause :: misc ( self . span ) ,
1358
1355
& all_substs,
1359
1356
& candidate. method_ty . generics ) ;
1360
1357
1361
1358
MethodCallee {
1362
- origin : candidate. origin ,
1359
+ origin : candidate. origin . clone ( ) ,
1363
1360
ty : fty,
1364
1361
substs : all_substs
1365
1362
}
@@ -1436,10 +1433,10 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1436
1433
MethodStaticUnboxedClosure ( _) => bad = false ,
1437
1434
// FIXME: does this properly enforce this on everything now
1438
1435
// that self has been merged in? -sully
1439
- MethodParam ( MethodParam { trait_id : trait_id , .. } ) |
1440
- MethodObject ( MethodObject { trait_id : trait_id , .. } ) => {
1436
+ MethodParam ( MethodParam { trait_ref : ref trait_ref , .. } ) |
1437
+ MethodObject ( MethodObject { trait_ref : ref trait_ref , .. } ) => {
1441
1438
bad = self . tcx ( ) . destructor_for_type . borrow ( )
1442
- . contains_key ( & trait_id ) ;
1439
+ . contains_key ( & trait_ref . def_id ) ;
1443
1440
}
1444
1441
}
1445
1442
@@ -1583,10 +1580,10 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
1583
1580
self . report_static_candidate ( idx, did)
1584
1581
}
1585
1582
MethodParam ( ref mp) => {
1586
- self . report_param_candidate ( idx, ( * mp ) . trait_id )
1583
+ self . report_param_candidate ( idx, mp . trait_ref . def_id )
1587
1584
}
1588
1585
MethodObject ( ref mo) => {
1589
- self . report_trait_candidate ( idx, mo. trait_id )
1586
+ self . report_trait_candidate ( idx, mo. trait_ref . def_id )
1590
1587
}
1591
1588
}
1592
1589
}
0 commit comments