@@ -370,8 +370,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
370370 self . suggest_fn_call ( & mut err, rcvr_expr, rcvr_ty, |output_ty| {
371371 let call_expr =
372372 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+ ) ;
375380 probe. is_ok ( )
376381 } ) ;
377382 }
@@ -1386,14 +1391,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13861391 let range_ty =
13871392 self . tcx . bound_type_of ( range_def_id) . subst ( self . tcx , & [ actual. into ( ) ] ) ;
13881393
1389- let pick = self . probe_for_name (
1390- Mode :: MethodCall ,
1394+ let pick = self . lookup_probe_for_diagnostic (
13911395 item_name,
1392- None ,
1393- IsSuggestion ( true ) ,
13941396 range_ty,
1395- expr. hir_id ,
1397+ expr,
13961398 ProbeScope :: AllTraits ,
1399+ None ,
13971400 ) ;
13981401 if pick. is_ok ( ) {
13991402 let range_span = parent_expr. span . with_hi ( expr. span . hi ( ) ) ;
@@ -1573,11 +1576,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15731576 && let Some ( expr) = visitor. result
15741577 && let Some ( self_ty) = self . node_ty_opt ( expr. hir_id )
15751578 {
1576- let probe = self . lookup_probe (
1579+ let probe = self . lookup_probe_for_diagnostic (
15771580 seg2. ident ,
15781581 self_ty,
15791582 call_expr,
15801583 ProbeScope :: TraitsInScope ,
1584+ None ,
15811585 ) ;
15821586 if probe. is_ok ( ) {
15831587 let sm = self . infcx . tcx . sess . source_map ( ) ;
@@ -1624,14 +1628,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16241628 self . check_for_nested_field_satisfying (
16251629 span,
16261630 & |_, field_ty| {
1627- self . probe_for_name (
1628- Mode :: MethodCall ,
1631+ self . lookup_probe_for_diagnostic (
16291632 item_name,
1630- return_type,
1631- IsSuggestion ( true ) ,
16321633 field_ty,
1633- call_expr. hir_id ,
1634+ call_expr,
16341635 ProbeScope :: TraitsInScope ,
1636+ return_type,
16351637 )
16361638 . map_or ( false , |pick| {
16371639 !never_mention_traits
@@ -1697,9 +1699,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16971699 return None ;
16981700 }
16991701
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) )
17031711 } )
17041712 . collect ( ) ;
17051713
@@ -1763,11 +1771,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17631771 ty:: AdtKind :: Struct | ty:: AdtKind :: Union => {
17641772 let [ first] = * * * substs else { return ; } ;
17651773 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 (
17671775 item_name,
17681776 ty,
17691777 call_expr,
17701778 ProbeScope :: TraitsInScope ,
1779+ None ,
17711780 ) else { return ; } ;
17721781
17731782 let name = self . ty_to_value_string ( actual) ;
@@ -2243,14 +2252,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22432252 ( self . tcx . mk_mut_ref ( self . tcx . lifetimes . re_erased , rcvr_ty) , "&mut " ) ,
22442253 ( self . tcx . mk_imm_ref ( self . tcx . lifetimes . re_erased , rcvr_ty) , "&" ) ,
22452254 ] {
2246- match self . probe_for_name (
2247- Mode :: MethodCall ,
2255+ match self . lookup_probe_for_diagnostic (
22482256 item_name,
2249- return_type,
2250- IsSuggestion ( true ) ,
22512257 * rcvr_ty,
2252- rcvr. hir_id ,
2258+ rcvr,
22532259 ProbeScope :: AllTraits ,
2260+ return_type,
22542261 ) {
22552262 Ok ( pick) => {
22562263 // 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> {
22842291 ( self . tcx . mk_diagnostic_item ( * rcvr_ty, sym:: Rc ) , "Rc::new" ) ,
22852292 ] {
22862293 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 (
22892295 item_name,
2290- return_type,
2291- IsSuggestion ( true ) ,
22922296 new_rcvr_t,
2293- rcvr. hir_id ,
2297+ rcvr,
22942298 ProbeScope :: AllTraits ,
2299+ return_type,
22952300 )
22962301 {
22972302 debug ! ( "try_alt_rcvr: pick candidate {:?}" , pick) ;
@@ -2670,11 +2675,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26702675 name : Symbol :: intern ( & format ! ( "{}_else" , method_name. as_str( ) ) ) ,
26712676 span : method_name. span ,
26722677 } ;
2673- let probe = self . lookup_probe (
2678+ let probe = self . lookup_probe_for_diagnostic (
26742679 new_name,
26752680 self_ty,
26762681 self_expr,
26772682 ProbeScope :: TraitsInScope ,
2683+ Some ( expected) ,
26782684 ) ;
26792685
26802686 // check the method arguments number
0 commit comments