@@ -35,6 +35,8 @@ use std::mem;
3535use std:: ops:: Deref ;
3636use std:: cmp:: max;
3737
38+ use smallvec:: { smallvec, SmallVec } ;
39+
3840use self :: CandidateKind :: * ;
3941pub use self :: PickKind :: * ;
4042
@@ -121,7 +123,7 @@ struct Candidate<'tcx> {
121123 xform_ret_ty : Option < Ty < ' tcx > > ,
122124 item : ty:: AssociatedItem ,
123125 kind : CandidateKind < ' tcx > ,
124- import_id : Option < hir:: HirId > ,
126+ import_ids : SmallVec < [ hir:: HirId ; 1 ] > ,
125127}
126128
127129#[ derive( Debug ) ]
@@ -146,7 +148,7 @@ enum ProbeResult {
146148pub struct Pick < ' tcx > {
147149 pub item : ty:: AssociatedItem ,
148150 pub kind : PickKind < ' tcx > ,
149- pub import_id : Option < hir:: HirId > ,
151+ pub import_ids : SmallVec < [ hir:: HirId ; 1 ] > ,
150152
151153 // Indicates that the source expression should be autoderef'd N times
152154 //
@@ -716,7 +718,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
716718 self . push_candidate ( Candidate {
717719 xform_self_ty, xform_ret_ty, item,
718720 kind : InherentImplCandidate ( impl_substs, obligations) ,
719- import_id : None
721+ import_ids : smallvec ! [ ]
720722 } , true ) ;
721723 }
722724 }
@@ -750,7 +752,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
750752 this. push_candidate ( Candidate {
751753 xform_self_ty, xform_ret_ty, item,
752754 kind : ObjectCandidate ,
753- import_id : None
755+ import_ids : smallvec ! [ ]
754756 } , true ) ;
755757 } ) ;
756758 }
@@ -799,7 +801,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
799801 this. push_candidate ( Candidate {
800802 xform_self_ty, xform_ret_ty, item,
801803 kind : WhereClauseCandidate ( poly_trait_ref) ,
802- import_id : None
804+ import_ids : smallvec ! [ ]
803805 } , true ) ;
804806 } ) ;
805807 }
@@ -838,9 +840,10 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
838840 for trait_candidate in applicable_traits. iter ( ) {
839841 let trait_did = trait_candidate. def_id ;
840842 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) ;
844847 result?;
845848 }
846849 }
@@ -852,7 +855,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
852855 let mut duplicates = FxHashSet :: default ( ) ;
853856 for trait_info in suggest:: all_traits ( self . tcx ) {
854857 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 ) ?;
856859 }
857860 }
858861 Ok ( ( ) )
@@ -890,7 +893,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
890893 }
891894
892895 fn assemble_extension_candidates_for_trait ( & mut self ,
893- import_id : Option < hir:: HirId > ,
896+ import_ids : SmallVec < [ hir:: HirId ; 1 ] > ,
894897 trait_def_id : DefId )
895898 -> Result < ( ) , MethodError < ' tcx > > {
896899 debug ! ( "assemble_extension_candidates_for_trait(trait_def_id={:?})" ,
@@ -907,7 +910,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
907910 let ( xform_self_ty, xform_ret_ty) =
908911 this. xform_self_ty ( & item, new_trait_ref. self_ty ( ) , new_trait_ref. substs ) ;
909912 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 ( ) ,
911914 kind : TraitCandidate ( new_trait_ref) ,
912915 } , true ) ;
913916 } ) ;
@@ -924,7 +927,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
924927 let ( xform_self_ty, xform_ret_ty) =
925928 self . xform_self_ty ( & item, trait_ref. self_ty ( ) , trait_substs) ;
926929 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 ( ) ,
928931 kind : TraitCandidate ( trait_ref) ,
929932 } , false ) ;
930933 }
@@ -1413,7 +1416,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
14131416 Some ( Pick {
14141417 item : probes[ 0 ] . 0 . item . clone ( ) ,
14151418 kind : TraitPick ,
1416- import_id : probes[ 0 ] . 0 . import_id ,
1419+ import_ids : probes[ 0 ] . 0 . import_ids . clone ( ) ,
14171420 autoderefs : 0 ,
14181421 autoref : None ,
14191422 unsize : None ,
@@ -1652,7 +1655,7 @@ impl<'tcx> Candidate<'tcx> {
16521655 WhereClausePick ( trait_ref. clone ( ) )
16531656 }
16541657 } ,
1655- import_id : self . import_id ,
1658+ import_ids : self . import_ids . clone ( ) ,
16561659 autoderefs : 0 ,
16571660 autoref : None ,
16581661 unsize : None ,
0 commit comments