@@ -7,6 +7,7 @@ use crate::check::autoderef::{self, Autoderef};
77use crate :: check:: FnCtxt ;
88use crate :: hir:: def_id:: DefId ;
99use crate :: hir:: def:: DefKind ;
10+ use crate :: hir:: SmallHirIdVec ;
1011use crate :: namespace:: Namespace ;
1112
1213use rustc_data_structures:: sync:: Lrc ;
@@ -35,6 +36,8 @@ use std::mem;
3536use std:: ops:: Deref ;
3637use std:: cmp:: max;
3738
39+ use smallvec:: smallvec;
40+
3841use self :: CandidateKind :: * ;
3942pub use self :: PickKind :: * ;
4043
@@ -121,7 +124,7 @@ struct Candidate<'tcx> {
121124 xform_ret_ty : Option < Ty < ' tcx > > ,
122125 item : ty:: AssociatedItem ,
123126 kind : CandidateKind < ' tcx > ,
124- import_id : Option < hir :: HirId > ,
127+ import_ids : SmallHirIdVec ,
125128}
126129
127130#[ derive( Debug ) ]
@@ -146,7 +149,7 @@ enum ProbeResult {
146149pub struct Pick < ' tcx > {
147150 pub item : ty:: AssociatedItem ,
148151 pub kind : PickKind < ' tcx > ,
149- pub import_id : Option < hir:: HirId > ,
152+ pub import_ids : hir:: SmallHirIdVec ,
150153
151154 // Indicates that the source expression should be autoderef'd N times
152155 //
@@ -716,7 +719,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
716719 self . push_candidate ( Candidate {
717720 xform_self_ty, xform_ret_ty, item,
718721 kind : InherentImplCandidate ( impl_substs, obligations) ,
719- import_id : None
722+ import_ids : smallvec ! [ ]
720723 } , true ) ;
721724 }
722725 }
@@ -750,7 +753,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
750753 this. push_candidate ( Candidate {
751754 xform_self_ty, xform_ret_ty, item,
752755 kind : ObjectCandidate ,
753- import_id : None
756+ import_ids : smallvec ! [ ]
754757 } , true ) ;
755758 } ) ;
756759 }
@@ -799,7 +802,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
799802 this. push_candidate ( Candidate {
800803 xform_self_ty, xform_ret_ty, item,
801804 kind : WhereClauseCandidate ( poly_trait_ref) ,
802- import_id : None
805+ import_ids : smallvec ! [ ]
803806 } , true ) ;
804807 } ) ;
805808 }
@@ -838,9 +841,10 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
838841 for trait_candidate in applicable_traits. iter ( ) {
839842 let trait_did = trait_candidate. def_id ;
840843 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) ;
844+ let import_ids = trait_candidate. import_ids . iter ( ) . map ( |node_id|
845+ self . fcx . tcx . hir ( ) . node_to_hir_id ( * node_id) ) . collect ( ) ;
846+ let result = self . assemble_extension_candidates_for_trait ( import_ids,
847+ trait_did) ;
844848 result?;
845849 }
846850 }
@@ -852,7 +856,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
852856 let mut duplicates = FxHashSet :: default ( ) ;
853857 for trait_info in suggest:: all_traits ( self . tcx ) {
854858 if duplicates. insert ( trait_info. def_id ) {
855- self . assemble_extension_candidates_for_trait ( None , trait_info. def_id ) ?;
859+ self . assemble_extension_candidates_for_trait ( smallvec ! [ ] , trait_info. def_id ) ?;
856860 }
857861 }
858862 Ok ( ( ) )
@@ -890,7 +894,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
890894 }
891895
892896 fn assemble_extension_candidates_for_trait ( & mut self ,
893- import_id : Option < hir :: HirId > ,
897+ import_ids : SmallHirIdVec ,
894898 trait_def_id : DefId )
895899 -> Result < ( ) , MethodError < ' tcx > > {
896900 debug ! ( "assemble_extension_candidates_for_trait(trait_def_id={:?})" ,
@@ -907,7 +911,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
907911 let ( xform_self_ty, xform_ret_ty) =
908912 this. xform_self_ty ( & item, new_trait_ref. self_ty ( ) , new_trait_ref. substs ) ;
909913 this. push_candidate ( Candidate {
910- xform_self_ty, xform_ret_ty, item, import_id ,
914+ xform_self_ty, xform_ret_ty, item, import_ids : import_ids . clone ( ) ,
911915 kind : TraitCandidate ( new_trait_ref) ,
912916 } , true ) ;
913917 } ) ;
@@ -924,7 +928,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
924928 let ( xform_self_ty, xform_ret_ty) =
925929 self . xform_self_ty ( & item, trait_ref. self_ty ( ) , trait_substs) ;
926930 self . push_candidate ( Candidate {
927- xform_self_ty, xform_ret_ty, item, import_id ,
931+ xform_self_ty, xform_ret_ty, item, import_ids : import_ids . clone ( ) ,
928932 kind : TraitCandidate ( trait_ref) ,
929933 } , false ) ;
930934 }
@@ -1413,7 +1417,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
14131417 Some ( Pick {
14141418 item : probes[ 0 ] . 0 . item . clone ( ) ,
14151419 kind : TraitPick ,
1416- import_id : probes[ 0 ] . 0 . import_id ,
1420+ import_ids : probes[ 0 ] . 0 . import_ids . clone ( ) ,
14171421 autoderefs : 0 ,
14181422 autoref : None ,
14191423 unsize : None ,
@@ -1652,7 +1656,7 @@ impl<'tcx> Candidate<'tcx> {
16521656 WhereClausePick ( trait_ref. clone ( ) )
16531657 }
16541658 } ,
1655- import_id : self . import_id ,
1659+ import_ids : self . import_ids . clone ( ) ,
16561660 autoderefs : 0 ,
16571661 autoref : None ,
16581662 unsize : None ,
0 commit comments