@@ -191,6 +191,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
191191 rcvr_opt : Option < & ' tcx hir:: Expr < ' tcx > > ,
192192 rcvr_ty : Ty < ' tcx > ,
193193 item_name : Ident ,
194+ expr_id : hir:: HirId ,
194195 source : SelfSource < ' tcx > ,
195196 error : MethodError < ' tcx > ,
196197 args : Option < & ' tcx [ hir:: Expr < ' tcx > ] > ,
@@ -216,6 +217,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
216217 rcvr_opt,
217218 rcvr_ty,
218219 item_name,
220+ expr_id,
219221 source,
220222 args,
221223 sugg_span,
@@ -551,6 +553,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
551553 rcvr_opt : Option < & ' tcx hir:: Expr < ' tcx > > ,
552554 rcvr_ty : Ty < ' tcx > ,
553555 item_name : Ident ,
556+ expr_id : hir:: HirId ,
554557 source : SelfSource < ' tcx > ,
555558 args : Option < & ' tcx [ hir:: Expr < ' tcx > ] > ,
556559 sugg_span : Span ,
@@ -683,7 +686,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
683686 }
684687
685688 if matches ! ( source, SelfSource :: QPath ( _) ) && args. is_some ( ) {
686- self . find_builder_fn ( & mut err, rcvr_ty) ;
689+ self . find_builder_fn ( & mut err, rcvr_ty, expr_id ) ;
687690 }
688691
689692 if tcx. ty_is_opaque_future ( rcvr_ty) && item_name. name == sym:: poll {
@@ -1944,7 +1947,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19441947
19451948 /// Look at all the associated functions without receivers in the type's inherent impls
19461949 /// to look for builders that return `Self`, `Option<Self>` or `Result<Self, _>`.
1947- fn find_builder_fn ( & self , err : & mut Diag < ' _ > , rcvr_ty : Ty < ' tcx > ) {
1950+ fn find_builder_fn ( & self , err : & mut Diag < ' _ > , rcvr_ty : Ty < ' tcx > , expr_id : hir :: HirId ) {
19481951 let ty:: Adt ( adt_def, _) = rcvr_ty. kind ( ) else {
19491952 return ;
19501953 } ;
@@ -1953,8 +1956,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19531956 let mut items = impls
19541957 . iter ( )
19551958 . flat_map ( |i| self . tcx . associated_items ( i) . in_definition_order ( ) )
1956- // Only assoc fn with no receivers.
1957- . filter ( |item| matches ! ( item. kind, ty:: AssocKind :: Fn ) && !item. fn_has_self_parameter )
1959+ // Only assoc fn with no receivers and only if
1960+ // they are resolvable
1961+ . filter ( |item| {
1962+ matches ! ( item. kind, ty:: AssocKind :: Fn )
1963+ && !item. fn_has_self_parameter
1964+ && self
1965+ . probe_for_name (
1966+ Mode :: Path ,
1967+ item. ident ( self . tcx ) ,
1968+ None ,
1969+ IsSuggestion ( false ) ,
1970+ rcvr_ty,
1971+ expr_id,
1972+ ProbeScope :: TraitsInScope ,
1973+ )
1974+ . is_ok ( )
1975+ } )
19581976 . filter_map ( |item| {
19591977 // Only assoc fns that return `Self`, `Option<Self>` or `Result<Self, _>`.
19601978 let ret_ty = self
0 commit comments