@@ -88,6 +88,11 @@ pub(crate) struct ProbeContext<'a, 'tcx> {
88
88
> ,
89
89
90
90
scope_expr_id : HirId ,
91
+
92
+ /// Is this probe being done for a diagnostic? This will skip some error reporting
93
+ /// machinery, since we don't particularly care about, for example, similarly named
94
+ /// candidates if we're *reporting* similarly named candidates.
95
+ is_suggestion : IsSuggestion ,
91
96
}
92
97
93
98
impl < ' a , ' tcx > Deref for ProbeContext < ' a , ' tcx > {
@@ -218,7 +223,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
218
223
/// would use to decide if a method is a plausible fit for
219
224
/// ambiguity purposes).
220
225
#[ instrument( level = "debug" , skip( self , candidate_filter) ) ]
221
- pub fn probe_for_return_type (
226
+ pub fn probe_for_return_type_for_diagnostic (
222
227
& self ,
223
228
span : Span ,
224
229
mode : Mode ,
@@ -457,6 +462,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
457
462
& orig_values,
458
463
steps. steps ,
459
464
scope_expr_id,
465
+ is_suggestion,
460
466
) ;
461
467
462
468
probe_cx. assemble_inherent_candidates ( ) ;
@@ -551,6 +557,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
551
557
orig_steps_var_values : & ' a OriginalQueryValues < ' tcx > ,
552
558
steps : & ' tcx [ CandidateStep < ' tcx > ] ,
553
559
scope_expr_id : HirId ,
560
+ is_suggestion : IsSuggestion ,
554
561
) -> ProbeContext < ' a , ' tcx > {
555
562
ProbeContext {
556
563
fcx,
@@ -568,6 +575,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
568
575
static_candidates : RefCell :: new ( Vec :: new ( ) ) ,
569
576
unsatisfied_predicates : RefCell :: new ( Vec :: new ( ) ) ,
570
577
scope_expr_id,
578
+ is_suggestion,
571
579
}
572
580
}
573
581
@@ -942,6 +950,18 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
942
950
return r;
943
951
}
944
952
953
+ // If it's a `lookup_probe_for_diagnostic`, then quit early. No need to
954
+ // probe for other candidates.
955
+ if self . is_suggestion . 0 {
956
+ return Err ( MethodError :: NoMatch ( NoMatchData {
957
+ static_candidates : vec ! [ ] ,
958
+ unsatisfied_predicates : vec ! [ ] ,
959
+ out_of_scope_traits : vec ! [ ] ,
960
+ similar_candidate : None ,
961
+ mode : self . mode ,
962
+ } ) ) ;
963
+ }
964
+
945
965
debug ! ( "pick: actual search failed, assemble diagnostics" ) ;
946
966
947
967
let static_candidates = std:: mem:: take ( self . static_candidates . get_mut ( ) ) ;
@@ -1633,6 +1653,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1633
1653
self . orig_steps_var_values ,
1634
1654
self . steps ,
1635
1655
self . scope_expr_id ,
1656
+ IsSuggestion ( true ) ,
1636
1657
) ;
1637
1658
pcx. allow_similar_names = true ;
1638
1659
pcx. assemble_inherent_candidates ( ) ;
0 commit comments