@@ -1143,7 +1143,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1143
1143
}
1144
1144
}
1145
1145
1146
- let label_span_not_found = |err : & mut Diag < ' _ > | {
1146
+ let mut find_candidate_for_method = false ;
1147
+
1148
+ let mut label_span_not_found = |err : & mut Diag < ' _ > | {
1147
1149
if unsatisfied_predicates. is_empty ( ) {
1148
1150
err. span_label ( span, format ! ( "{item_kind} not found in `{ty_str}`" ) ) ;
1149
1151
let is_string_or_ref_str = match rcvr_ty. kind ( ) {
@@ -1219,6 +1221,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1219
1221
err. note ( format ! (
1220
1222
"the {item_kind} was found for\n {type_candidates}{additional_types}"
1221
1223
) ) ;
1224
+ find_candidate_for_method = mode == Mode :: MethodCall ;
1222
1225
}
1223
1226
}
1224
1227
} else {
@@ -1371,9 +1374,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1371
1374
) ;
1372
1375
}
1373
1376
}
1374
- // If an appropriate error source is not found, check method chain for possible candiates
1375
- if unsatisfied_predicates. is_empty ( )
1376
- && let Mode :: MethodCall = mode
1377
+
1378
+ if !find_candidate_for_method {
1379
+ self . lookup_segments_chain_for_no_match_method (
1380
+ & mut err,
1381
+ item_name,
1382
+ item_kind,
1383
+ source,
1384
+ no_match_data,
1385
+ ) ;
1386
+ }
1387
+
1388
+ self . note_derefed_ty_has_method ( & mut err, source, rcvr_ty, item_name, expected) ;
1389
+ Some ( err)
1390
+ }
1391
+
1392
+ /// If an appropriate error source is not found, check method chain for possible candidates
1393
+ fn lookup_segments_chain_for_no_match_method (
1394
+ & self ,
1395
+ err : & mut Diag < ' _ > ,
1396
+ item_name : Ident ,
1397
+ item_kind : & str ,
1398
+ source : SelfSource < ' tcx > ,
1399
+ no_match_data : & NoMatchData < ' tcx > ,
1400
+ ) {
1401
+ if no_match_data. unsatisfied_predicates . is_empty ( )
1402
+ && let Mode :: MethodCall = no_match_data. mode
1377
1403
&& let SelfSource :: MethodCall ( mut source_expr) = source
1378
1404
{
1379
1405
let mut stack_methods = vec ! [ ] ;
@@ -1394,6 +1420,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1394
1420
. unwrap_or ( Ty :: new_misc_error ( self . tcx ) ) ,
1395
1421
) ;
1396
1422
1423
+ // FIXME: `probe_for_name_many` searches for methods in inherent implementations,
1424
+ // so it may return a candidate that doesn't belong to this `revr_ty`. We need to
1425
+ // check whether the instantiated type matches the received one.
1397
1426
for _matched_method in self . probe_for_name_many (
1398
1427
Mode :: MethodCall ,
1399
1428
item_name,
@@ -1416,8 +1445,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1416
1445
) ;
1417
1446
}
1418
1447
}
1419
- self . note_derefed_ty_has_method ( & mut err, source, rcvr_ty, item_name, expected) ;
1420
- Some ( err)
1421
1448
}
1422
1449
1423
1450
fn find_likely_intended_associated_item (
0 commit comments