@@ -252,14 +252,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
252
252
/// would result in an error (basically, the same criteria we
253
253
/// would use to decide if a method is a plausible fit for
254
254
/// ambiguity purposes).
255
- #[ instrument( level = "debug" , skip( self ) ) ]
255
+ #[ instrument( level = "debug" , skip( self , candidate_filter ) ) ]
256
256
pub fn probe_for_return_type (
257
257
& self ,
258
258
span : Span ,
259
259
mode : Mode ,
260
260
return_type : Ty < ' tcx > ,
261
261
self_ty : Ty < ' tcx > ,
262
262
scope_expr_id : hir:: HirId ,
263
+ candidate_filter : impl Fn ( & ty:: AssocItem ) -> bool ,
263
264
) -> Vec < ty:: AssocItem > {
264
265
let method_names = self
265
266
. probe_op (
@@ -271,7 +272,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
271
272
self_ty,
272
273
scope_expr_id,
273
274
ProbeScope :: AllTraits ,
274
- |probe_cx| Ok ( probe_cx. candidate_method_names ( ) ) ,
275
+ |probe_cx| Ok ( probe_cx. candidate_method_names ( candidate_filter ) ) ,
275
276
)
276
277
. unwrap_or_default ( ) ;
277
278
method_names
@@ -966,12 +967,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
966
967
}
967
968
}
968
969
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 > {
970
974
let mut set = FxHashSet :: default ( ) ;
971
975
let mut names: Vec < _ > = self
972
976
. inherent_candidates
973
977
. iter ( )
974
978
. chain ( & self . extension_candidates )
979
+ . filter ( |candidate| candidate_filter ( & candidate. item ) )
975
980
. filter ( |candidate| {
976
981
if let Some ( return_ty) = self . return_type {
977
982
self . matches_return_type ( & candidate. item , None , return_ty)
@@ -1689,7 +1694,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1689
1694
pcx. allow_similar_names = true ;
1690
1695
pcx. assemble_inherent_candidates ( ) ;
1691
1696
1692
- let method_names = pcx. candidate_method_names ( ) ;
1697
+ let method_names = pcx. candidate_method_names ( |_| true ) ;
1693
1698
pcx. allow_similar_names = false ;
1694
1699
let applicable_close_candidates: Vec < ty:: AssocItem > = method_names
1695
1700
. iter ( )
0 commit comments