@@ -370,8 +370,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
370
370
self . suggest_fn_call ( & mut err, rcvr_expr, rcvr_ty, |output_ty| {
371
371
let call_expr =
372
372
self . tcx . hir ( ) . expect_expr ( self . tcx . hir ( ) . parent_id ( rcvr_expr. hir_id ) ) ;
373
- let probe =
374
- self . lookup_probe ( item_name, output_ty, call_expr, ProbeScope :: AllTraits ) ;
373
+ let probe = self . lookup_probe_for_diagnostic (
374
+ item_name,
375
+ output_ty,
376
+ call_expr,
377
+ ProbeScope :: AllTraits ,
378
+ expected. only_has_type ( self ) ,
379
+ ) ;
375
380
probe. is_ok ( )
376
381
} ) ;
377
382
}
@@ -1386,14 +1391,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1386
1391
let range_ty =
1387
1392
self . tcx . bound_type_of ( range_def_id) . subst ( self . tcx , & [ actual. into ( ) ] ) ;
1388
1393
1389
- let pick = self . probe_for_name (
1390
- Mode :: MethodCall ,
1394
+ let pick = self . lookup_probe_for_diagnostic (
1391
1395
item_name,
1392
- None ,
1393
- IsSuggestion ( true ) ,
1394
1396
range_ty,
1395
- expr. hir_id ,
1397
+ expr,
1396
1398
ProbeScope :: AllTraits ,
1399
+ None ,
1397
1400
) ;
1398
1401
if pick. is_ok ( ) {
1399
1402
let range_span = parent_expr. span . with_hi ( expr. span . hi ( ) ) ;
@@ -1573,11 +1576,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1573
1576
&& let Some ( expr) = visitor. result
1574
1577
&& let Some ( self_ty) = self . node_ty_opt ( expr. hir_id )
1575
1578
{
1576
- let probe = self . lookup_probe (
1579
+ let probe = self . lookup_probe_for_diagnostic (
1577
1580
seg2. ident ,
1578
1581
self_ty,
1579
1582
call_expr,
1580
1583
ProbeScope :: TraitsInScope ,
1584
+ None ,
1581
1585
) ;
1582
1586
if probe. is_ok ( ) {
1583
1587
let sm = self . infcx . tcx . sess . source_map ( ) ;
@@ -1624,14 +1628,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1624
1628
self . check_for_nested_field_satisfying (
1625
1629
span,
1626
1630
& |_, field_ty| {
1627
- self . probe_for_name (
1628
- Mode :: MethodCall ,
1631
+ self . lookup_probe_for_diagnostic (
1629
1632
item_name,
1630
- return_type,
1631
- IsSuggestion ( true ) ,
1632
1633
field_ty,
1633
- call_expr. hir_id ,
1634
+ call_expr,
1634
1635
ProbeScope :: TraitsInScope ,
1636
+ return_type,
1635
1637
)
1636
1638
. map_or ( false , |pick| {
1637
1639
!never_mention_traits
@@ -1697,9 +1699,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1697
1699
return None ;
1698
1700
}
1699
1701
1700
- self . lookup_probe ( item_name, field_ty, call_expr, ProbeScope :: TraitsInScope )
1701
- . ok ( )
1702
- . map ( |pick| ( variant, field, pick) )
1702
+ self . lookup_probe_for_diagnostic (
1703
+ item_name,
1704
+ field_ty,
1705
+ call_expr,
1706
+ ProbeScope :: TraitsInScope ,
1707
+ None ,
1708
+ )
1709
+ . ok ( )
1710
+ . map ( |pick| ( variant, field, pick) )
1703
1711
} )
1704
1712
. collect ( ) ;
1705
1713
@@ -1763,11 +1771,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1763
1771
ty:: AdtKind :: Struct | ty:: AdtKind :: Union => {
1764
1772
let [ first] = * * * substs else { return ; } ;
1765
1773
let ty:: GenericArgKind :: Type ( ty) = first. unpack ( ) else { return ; } ;
1766
- let Ok ( pick) = self . lookup_probe (
1774
+ let Ok ( pick) = self . lookup_probe_for_diagnostic (
1767
1775
item_name,
1768
1776
ty,
1769
1777
call_expr,
1770
1778
ProbeScope :: TraitsInScope ,
1779
+ None ,
1771
1780
) else { return ; } ;
1772
1781
1773
1782
let name = self . ty_to_value_string ( actual) ;
@@ -2243,14 +2252,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2243
2252
( self . tcx . mk_mut_ref ( self . tcx . lifetimes . re_erased , rcvr_ty) , "&mut " ) ,
2244
2253
( self . tcx . mk_imm_ref ( self . tcx . lifetimes . re_erased , rcvr_ty) , "&" ) ,
2245
2254
] {
2246
- match self . probe_for_name (
2247
- Mode :: MethodCall ,
2255
+ match self . lookup_probe_for_diagnostic (
2248
2256
item_name,
2249
- return_type,
2250
- IsSuggestion ( true ) ,
2251
2257
* rcvr_ty,
2252
- rcvr. hir_id ,
2258
+ rcvr,
2253
2259
ProbeScope :: AllTraits ,
2260
+ return_type,
2254
2261
) {
2255
2262
Ok ( pick) => {
2256
2263
// If the method is defined for the receiver we have, it likely wasn't `use`d.
@@ -2284,14 +2291,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2284
2291
( self . tcx . mk_diagnostic_item ( * rcvr_ty, sym:: Rc ) , "Rc::new" ) ,
2285
2292
] {
2286
2293
if let Some ( new_rcvr_t) = * rcvr_ty
2287
- && let Ok ( pick) = self . probe_for_name (
2288
- Mode :: MethodCall ,
2294
+ && let Ok ( pick) = self . lookup_probe_for_diagnostic (
2289
2295
item_name,
2290
- return_type,
2291
- IsSuggestion ( true ) ,
2292
2296
new_rcvr_t,
2293
- rcvr. hir_id ,
2297
+ rcvr,
2294
2298
ProbeScope :: AllTraits ,
2299
+ return_type,
2295
2300
)
2296
2301
{
2297
2302
debug ! ( "try_alt_rcvr: pick candidate {:?}" , pick) ;
@@ -2670,11 +2675,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2670
2675
name : Symbol :: intern ( & format ! ( "{}_else" , method_name. as_str( ) ) ) ,
2671
2676
span : method_name. span ,
2672
2677
} ;
2673
- let probe = self . lookup_probe (
2678
+ let probe = self . lookup_probe_for_diagnostic (
2674
2679
new_name,
2675
2680
self_ty,
2676
2681
self_expr,
2677
2682
ProbeScope :: TraitsInScope ,
2683
+ Some ( expected) ,
2678
2684
) ;
2679
2685
2680
2686
// check the method arguments number
0 commit comments