@@ -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,
@@ -549,6 +551,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
549551 rcvr_opt : Option < & ' tcx hir:: Expr < ' tcx > > ,
550552 rcvr_ty : Ty < ' tcx > ,
551553 item_name : Ident ,
554+ expr_id : hir:: HirId ,
552555 source : SelfSource < ' tcx > ,
553556 args : Option < & ' tcx [ hir:: Expr < ' tcx > ] > ,
554557 sugg_span : Span ,
@@ -681,7 +684,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
681684 }
682685
683686 if matches ! ( source, SelfSource :: QPath ( _) ) && args. is_some ( ) {
684- self . find_builder_fn ( & mut err, rcvr_ty) ;
687+ self . find_builder_fn ( & mut err, rcvr_ty, expr_id ) ;
685688 }
686689
687690 if tcx. ty_is_opaque_future ( rcvr_ty) && item_name. name == sym:: poll {
@@ -1942,7 +1945,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19421945
19431946 /// Look at all the associated functions without receivers in the type's inherent impls
19441947 /// to look for builders that return `Self`, `Option<Self>` or `Result<Self, _>`.
1945- fn find_builder_fn ( & self , err : & mut Diag < ' _ > , rcvr_ty : Ty < ' tcx > ) {
1948+ fn find_builder_fn ( & self , err : & mut Diag < ' _ > , rcvr_ty : Ty < ' tcx > , expr_id : hir :: HirId ) {
19461949 let ty:: Adt ( adt_def, _) = rcvr_ty. kind ( ) else {
19471950 return ;
19481951 } ;
@@ -1951,8 +1954,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19511954 let mut items = impls
19521955 . iter ( )
19531956 . flat_map ( |i| self . tcx . associated_items ( i) . in_definition_order ( ) )
1954- // Only assoc fn with no receivers.
1955- . filter ( |item| matches ! ( item. kind, ty:: AssocKind :: Fn ) && !item. fn_has_self_parameter )
1957+ // Only assoc fn with no receivers and only if
1958+ // they are resolvable
1959+ . filter ( |item| {
1960+ matches ! ( item. kind, ty:: AssocKind :: Fn )
1961+ && !item. fn_has_self_parameter
1962+ && self
1963+ . probe_for_name (
1964+ Mode :: Path ,
1965+ item. ident ( self . tcx ) ,
1966+ None ,
1967+ IsSuggestion ( true ) ,
1968+ rcvr_ty,
1969+ expr_id,
1970+ ProbeScope :: TraitsInScope ,
1971+ )
1972+ . is_ok ( )
1973+ } )
19561974 . filter_map ( |item| {
19571975 // Only assoc fns that return `Self`, `Option<Self>` or `Result<Self, _>`.
19581976 let ret_ty = self
0 commit comments