@@ -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,
@@ -551,6 +553,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
551
553
rcvr_opt : Option < & ' tcx hir:: Expr < ' tcx > > ,
552
554
rcvr_ty : Ty < ' tcx > ,
553
555
item_name : Ident ,
556
+ expr_id : hir:: HirId ,
554
557
source : SelfSource < ' tcx > ,
555
558
args : Option < & ' tcx [ hir:: Expr < ' tcx > ] > ,
556
559
sugg_span : Span ,
@@ -683,7 +686,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
683
686
}
684
687
685
688
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 ) ;
687
690
}
688
691
689
692
if tcx. ty_is_opaque_future ( rcvr_ty) && item_name. name == sym:: poll {
@@ -1944,7 +1947,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1944
1947
1945
1948
/// Look at all the associated functions without receivers in the type's inherent impls
1946
1949
/// 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 ) {
1948
1951
let ty:: Adt ( adt_def, _) = rcvr_ty. kind ( ) else {
1949
1952
return ;
1950
1953
} ;
@@ -1953,8 +1956,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1953
1956
let mut items = impls
1954
1957
. iter ( )
1955
1958
. 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 ( true ) ,
1970
+ rcvr_ty,
1971
+ expr_id,
1972
+ ProbeScope :: TraitsInScope ,
1973
+ )
1974
+ . is_ok ( )
1975
+ } )
1958
1976
. filter_map ( |item| {
1959
1977
// Only assoc fns that return `Self`, `Option<Self>` or `Result<Self, _>`.
1960
1978
let ret_ty = self
0 commit comments