@@ -35,6 +35,8 @@ use std::mem;
35
35
use std:: ops:: Deref ;
36
36
use std:: cmp:: max;
37
37
38
+ use smallvec:: { smallvec, SmallVec } ;
39
+
38
40
use self :: CandidateKind :: * ;
39
41
pub use self :: PickKind :: * ;
40
42
@@ -121,7 +123,7 @@ struct Candidate<'tcx> {
121
123
xform_ret_ty : Option < Ty < ' tcx > > ,
122
124
item : ty:: AssociatedItem ,
123
125
kind : CandidateKind < ' tcx > ,
124
- import_id : Option < hir:: HirId > ,
126
+ import_ids : SmallVec < [ hir:: HirId ; 1 ] > ,
125
127
}
126
128
127
129
#[ derive( Debug ) ]
@@ -146,7 +148,7 @@ enum ProbeResult {
146
148
pub struct Pick < ' tcx > {
147
149
pub item : ty:: AssociatedItem ,
148
150
pub kind : PickKind < ' tcx > ,
149
- pub import_id : Option < hir:: HirId > ,
151
+ pub import_ids : SmallVec < [ hir:: HirId ; 1 ] > ,
150
152
151
153
// Indicates that the source expression should be autoderef'd N times
152
154
//
@@ -716,7 +718,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
716
718
self . push_candidate ( Candidate {
717
719
xform_self_ty, xform_ret_ty, item,
718
720
kind : InherentImplCandidate ( impl_substs, obligations) ,
719
- import_id : None
721
+ import_ids : smallvec ! [ ]
720
722
} , true ) ;
721
723
}
722
724
}
@@ -750,7 +752,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
750
752
this. push_candidate ( Candidate {
751
753
xform_self_ty, xform_ret_ty, item,
752
754
kind : ObjectCandidate ,
753
- import_id : None
755
+ import_ids : smallvec ! [ ]
754
756
} , true ) ;
755
757
} ) ;
756
758
}
@@ -799,7 +801,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
799
801
this. push_candidate ( Candidate {
800
802
xform_self_ty, xform_ret_ty, item,
801
803
kind : WhereClauseCandidate ( poly_trait_ref) ,
802
- import_id : None
804
+ import_ids : smallvec ! [ ]
803
805
} , true ) ;
804
806
} ) ;
805
807
}
@@ -838,9 +840,10 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
838
840
for trait_candidate in applicable_traits. iter ( ) {
839
841
let trait_did = trait_candidate. def_id ;
840
842
if duplicates. insert ( trait_did) {
841
- let import_id = trait_candidate. import_id . map ( |node_id|
842
- self . fcx . tcx . hir ( ) . node_to_hir_id ( node_id) ) ;
843
- let result = self . assemble_extension_candidates_for_trait ( import_id, trait_did) ;
843
+ let import_ids = trait_candidate. import_ids . iter ( ) . map ( |node_id|
844
+ self . fcx . tcx . hir ( ) . node_to_hir_id ( * node_id) ) . collect ( ) ;
845
+ let result = self . assemble_extension_candidates_for_trait ( import_ids,
846
+ trait_did) ;
844
847
result?;
845
848
}
846
849
}
@@ -852,7 +855,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
852
855
let mut duplicates = FxHashSet :: default ( ) ;
853
856
for trait_info in suggest:: all_traits ( self . tcx ) {
854
857
if duplicates. insert ( trait_info. def_id ) {
855
- self . assemble_extension_candidates_for_trait ( None , trait_info. def_id ) ?;
858
+ self . assemble_extension_candidates_for_trait ( smallvec ! [ ] , trait_info. def_id ) ?;
856
859
}
857
860
}
858
861
Ok ( ( ) )
@@ -890,7 +893,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
890
893
}
891
894
892
895
fn assemble_extension_candidates_for_trait ( & mut self ,
893
- import_id : Option < hir:: HirId > ,
896
+ import_ids : SmallVec < [ hir:: HirId ; 1 ] > ,
894
897
trait_def_id : DefId )
895
898
-> Result < ( ) , MethodError < ' tcx > > {
896
899
debug ! ( "assemble_extension_candidates_for_trait(trait_def_id={:?})" ,
@@ -907,7 +910,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
907
910
let ( xform_self_ty, xform_ret_ty) =
908
911
this. xform_self_ty ( & item, new_trait_ref. self_ty ( ) , new_trait_ref. substs ) ;
909
912
this. push_candidate ( Candidate {
910
- xform_self_ty, xform_ret_ty, item, import_id ,
913
+ xform_self_ty, xform_ret_ty, item, import_ids : import_ids . clone ( ) ,
911
914
kind : TraitCandidate ( new_trait_ref) ,
912
915
} , true ) ;
913
916
} ) ;
@@ -924,7 +927,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
924
927
let ( xform_self_ty, xform_ret_ty) =
925
928
self . xform_self_ty ( & item, trait_ref. self_ty ( ) , trait_substs) ;
926
929
self . push_candidate ( Candidate {
927
- xform_self_ty, xform_ret_ty, item, import_id ,
930
+ xform_self_ty, xform_ret_ty, item, import_ids : import_ids . clone ( ) ,
928
931
kind : TraitCandidate ( trait_ref) ,
929
932
} , false ) ;
930
933
}
@@ -1413,7 +1416,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
1413
1416
Some ( Pick {
1414
1417
item : probes[ 0 ] . 0 . item . clone ( ) ,
1415
1418
kind : TraitPick ,
1416
- import_id : probes[ 0 ] . 0 . import_id ,
1419
+ import_ids : probes[ 0 ] . 0 . import_ids . clone ( ) ,
1417
1420
autoderefs : 0 ,
1418
1421
autoref : None ,
1419
1422
unsize : None ,
@@ -1652,7 +1655,7 @@ impl<'tcx> Candidate<'tcx> {
1652
1655
WhereClausePick ( trait_ref. clone ( ) )
1653
1656
}
1654
1657
} ,
1655
- import_id : self . import_id ,
1658
+ import_ids : self . import_ids . clone ( ) ,
1656
1659
autoderefs : 0 ,
1657
1660
autoref : None ,
1658
1661
unsize : None ,
0 commit comments