@@ -252,14 +252,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
252252 /// would result in an error (basically, the same criteria we
253253 /// would use to decide if a method is a plausible fit for
254254 /// ambiguity purposes).
255- #[ instrument( level = "debug" , skip( self ) ) ]
255+ #[ instrument( level = "debug" , skip( self , candidate_filter ) ) ]
256256 pub fn probe_for_return_type (
257257 & self ,
258258 span : Span ,
259259 mode : Mode ,
260260 return_type : Ty < ' tcx > ,
261261 self_ty : Ty < ' tcx > ,
262262 scope_expr_id : hir:: HirId ,
263+ candidate_filter : impl Fn ( & ty:: AssocItem ) -> bool ,
263264 ) -> Vec < ty:: AssocItem > {
264265 let method_names = self
265266 . probe_op (
@@ -271,7 +272,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
271272 self_ty,
272273 scope_expr_id,
273274 ProbeScope :: AllTraits ,
274- |probe_cx| Ok ( probe_cx. candidate_method_names ( ) ) ,
275+ |probe_cx| Ok ( probe_cx. candidate_method_names ( candidate_filter ) ) ,
275276 )
276277 . unwrap_or_default ( ) ;
277278 method_names
@@ -966,12 +967,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
966967 }
967968 }
968969
969- fn candidate_method_names ( & self ) -> Vec < Ident > {
970+ fn candidate_method_names (
971+ & self ,
972+ candidate_filter : impl Fn ( & ty:: AssocItem ) -> bool ,
973+ ) -> Vec < Ident > {
970974 let mut set = FxHashSet :: default ( ) ;
971975 let mut names: Vec < _ > = self
972976 . inherent_candidates
973977 . iter ( )
974978 . chain ( & self . extension_candidates )
979+ . filter ( |candidate| candidate_filter ( & candidate. item ) )
975980 . filter ( |candidate| {
976981 if let Some ( return_ty) = self . return_type {
977982 self . matches_return_type ( & candidate. item , None , return_ty)
@@ -1689,7 +1694,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
16891694 pcx. allow_similar_names = true ;
16901695 pcx. assemble_inherent_candidates ( ) ;
16911696
1692- let method_names = pcx. candidate_method_names ( ) ;
1697+ let method_names = pcx. candidate_method_names ( |_| true ) ;
16931698 pcx. allow_similar_names = false ;
16941699 let applicable_close_candidates: Vec < ty:: AssocItem > = method_names
16951700 . iter ( )
0 commit comments