@@ -148,41 +148,41 @@ pub enum Mode {
148148}
149149
150150impl < ' a , ' gcx , ' tcx > FnCtxt < ' a , ' gcx , ' tcx > {
151- pub fn probe_return ( & self ,
152- span : Span ,
153- mode : Mode ,
154- return_type : Ty < ' tcx > ,
155- self_ty : Ty < ' tcx > ,
156- scope_expr_id : ast:: NodeId )
157- -> PickResult < ' tcx > {
151+ pub fn probe_for_return_type ( & self ,
152+ span : Span ,
153+ mode : Mode ,
154+ return_type : Ty < ' tcx > ,
155+ self_ty : Ty < ' tcx > ,
156+ scope_expr_id : ast:: NodeId )
157+ -> PickResult < ' tcx > {
158158 debug ! ( "probe(self_ty={:?}, return_type={}, scope_expr_id={})" ,
159159 self_ty,
160160 return_type,
161161 scope_expr_id) ;
162- self . _probe ( span, mode, LookingFor :: ReturnType ( return_type) , self_ty, scope_expr_id)
162+ self . probe_for ( span, mode, LookingFor :: ReturnType ( return_type) , self_ty, scope_expr_id)
163163 }
164164
165- pub fn probe_method ( & self ,
166- span : Span ,
167- mode : Mode ,
168- item_name : ast:: Name ,
169- self_ty : Ty < ' tcx > ,
170- scope_expr_id : ast:: NodeId )
171- -> PickResult < ' tcx > {
165+ pub fn probe_for_name ( & self ,
166+ span : Span ,
167+ mode : Mode ,
168+ item_name : ast:: Name ,
169+ self_ty : Ty < ' tcx > ,
170+ scope_expr_id : ast:: NodeId )
171+ -> PickResult < ' tcx > {
172172 debug ! ( "probe(self_ty={:?}, item_name={}, scope_expr_id={})" ,
173173 self_ty,
174174 item_name,
175175 scope_expr_id) ;
176- self . _probe ( span, mode, LookingFor :: MethodName ( item_name) , self_ty, scope_expr_id)
176+ self . probe_for ( span, mode, LookingFor :: MethodName ( item_name) , self_ty, scope_expr_id)
177177 }
178178
179- fn _probe ( & self ,
180- span : Span ,
181- mode : Mode ,
182- looking_for : LookingFor < ' tcx > ,
183- self_ty : Ty < ' tcx > ,
184- scope_expr_id : ast:: NodeId )
185- -> PickResult < ' tcx > {
179+ fn probe_for ( & self ,
180+ span : Span ,
181+ mode : Mode ,
182+ looking_for : LookingFor < ' tcx > ,
183+ self_ty : Ty < ' tcx > ,
184+ scope_expr_id : ast:: NodeId )
185+ -> PickResult < ' tcx > {
186186
187187 // FIXME(#18741) -- right now, creating the steps involves evaluating the
188188 // `*` operator, which registers obligations that then escape into
@@ -263,6 +263,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
263263
264264 let final_ty = match looking_for {
265265 & LookingFor :: MethodName ( _) => autoderef. unambiguous_final_ty ( ) ,
266+ // Since ReturnType case tries to coerce the returned type to the
267+ // expected one, we need all the information!
266268 & LookingFor :: ReturnType ( _) => self_ty,
267269 } ;
268270 match final_ty. sty {
@@ -636,10 +638,10 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
636638 match * method {
637639 ty:: ImplOrTraitItem :: MethodTraitItem ( ref x) => {
638640 self . probe ( |_| {
639- let output = self . replace_late_bound_regions_with_fresh_var (
640- self . span , infer:: FnCall , & x. fty . sig . output ( ) ) ;
641641 let substs = self . fresh_substs_for_item ( self . span , method. def_id ( ) ) ;
642- let output = output. 0 . subst ( self . tcx , substs) ;
642+ let output = x. fty . sig . output ( ) . subst ( self . tcx , substs) ;
643+ let ( output, _) = self . replace_late_bound_regions_with_fresh_var (
644+ self . span , infer:: FnCall , & output) ;
643645 self . can_sub_types ( output, expected) . is_ok ( )
644646 } )
645647 }
@@ -958,10 +960,17 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
958960 let steps = self . steps . clone ( ) ;
959961
960962 match self . looking_for {
961- LookingFor :: MethodName ( _) => steps. iter ( )
962- . filter_map ( |step| self . pick_step ( step) )
963- . next ( ) ,
963+ LookingFor :: MethodName ( _) => {
964+ // find the first step that works
965+ steps. iter ( )
966+ . filter_map ( |step| self . pick_step ( step) )
967+ . next ( )
968+ }
964969 LookingFor :: ReturnType ( _) => {
970+ // Normally, we stop at the first step where we find a positive match.
971+ // But when we are scanning for methods with a suitable return type,
972+ // these methods have distinct names and hence may not shadow one another
973+ // (also, this is just for hints, so precision is less important).
965974 let mut ret = Vec :: new ( ) ;
966975
967976 for step in steps. iter ( ) {
@@ -1058,10 +1067,9 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
10581067 match self . looking_for {
10591068 LookingFor :: MethodName ( _) => it. nth ( 0 ) ,
10601069 LookingFor :: ReturnType ( _) => {
1061- let mut ret = Vec :: new ( ) ;
1062- it. filter_map ( |entry| entry. ok ( ) )
1063- . map ( |mut v| { ret. append ( & mut v) ; } )
1064- . all ( |_| true ) ;
1070+ let ret = it. filter_map ( |entry| entry. ok ( ) )
1071+ . flat_map ( |v| v)
1072+ . collect :: < Vec < _ > > ( ) ;
10651073
10661074 if ret. len ( ) < 1 {
10671075 None
0 commit comments