@@ -191,6 +191,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
191
191
rcvr_opt : Option < & ' tcx hir:: Expr < ' tcx > > ,
192
192
rcvr_ty : Ty < ' tcx > ,
193
193
item_name : Ident ,
194
+ expr_id : hir:: HirId ,
194
195
source : SelfSource < ' tcx > ,
195
196
error : MethodError < ' tcx > ,
196
197
args : Option < & ' tcx [ hir:: Expr < ' tcx > ] > ,
@@ -216,6 +217,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
216
217
rcvr_opt,
217
218
rcvr_ty,
218
219
item_name,
220
+ expr_id,
219
221
source,
220
222
args,
221
223
sugg_span,
@@ -549,6 +551,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
549
551
rcvr_opt : Option < & ' tcx hir:: Expr < ' tcx > > ,
550
552
rcvr_ty : Ty < ' tcx > ,
551
553
item_name : Ident ,
554
+ expr_id : hir:: HirId ,
552
555
source : SelfSource < ' tcx > ,
553
556
args : Option < & ' tcx [ hir:: Expr < ' tcx > ] > ,
554
557
sugg_span : Span ,
@@ -681,7 +684,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
681
684
}
682
685
683
686
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 ) ;
685
688
}
686
689
687
690
if tcx. ty_is_opaque_future ( rcvr_ty) && item_name. name == sym:: poll {
@@ -1942,7 +1945,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1942
1945
1943
1946
/// Look at all the associated functions without receivers in the type's inherent impls
1944
1947
/// 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 ) {
1946
1949
let ty:: Adt ( adt_def, _) = rcvr_ty. kind ( ) else {
1947
1950
return ;
1948
1951
} ;
@@ -1951,8 +1954,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1951
1954
let mut items = impls
1952
1955
. iter ( )
1953
1956
. 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
+ } )
1956
1974
. filter_map ( |item| {
1957
1975
// Only assoc fns that return `Self`, `Option<Self>` or `Result<Self, _>`.
1958
1976
let ret_ty = self
0 commit comments