@@ -88,6 +88,11 @@ pub(crate) struct ProbeContext<'a, 'tcx> {
8888 > ,
8989
9090 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 ,
9196}
9297
9398impl < ' a , ' tcx > Deref for ProbeContext < ' a , ' tcx > {
@@ -218,7 +223,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
218223 /// would use to decide if a method is a plausible fit for
219224 /// ambiguity purposes).
220225 #[ instrument( level = "debug" , skip( self , candidate_filter) ) ]
221- pub fn probe_for_return_type (
226+ pub fn probe_for_return_type_for_diagnostic (
222227 & self ,
223228 span : Span ,
224229 mode : Mode ,
@@ -457,6 +462,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
457462 & orig_values,
458463 steps. steps ,
459464 scope_expr_id,
465+ is_suggestion,
460466 ) ;
461467
462468 probe_cx. assemble_inherent_candidates ( ) ;
@@ -551,6 +557,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
551557 orig_steps_var_values : & ' a OriginalQueryValues < ' tcx > ,
552558 steps : & ' tcx [ CandidateStep < ' tcx > ] ,
553559 scope_expr_id : HirId ,
560+ is_suggestion : IsSuggestion ,
554561 ) -> ProbeContext < ' a , ' tcx > {
555562 ProbeContext {
556563 fcx,
@@ -568,6 +575,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
568575 static_candidates : RefCell :: new ( Vec :: new ( ) ) ,
569576 unsatisfied_predicates : RefCell :: new ( Vec :: new ( ) ) ,
570577 scope_expr_id,
578+ is_suggestion,
571579 }
572580 }
573581
@@ -942,6 +950,18 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
942950 return r;
943951 }
944952
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+
945965 debug ! ( "pick: actual search failed, assemble diagnostics" ) ;
946966
947967 let static_candidates = std:: mem:: take ( self . static_candidates . get_mut ( ) ) ;
@@ -1633,6 +1653,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
16331653 self . orig_steps_var_values ,
16341654 self . steps ,
16351655 self . scope_expr_id ,
1656+ IsSuggestion ( true ) ,
16361657 ) ;
16371658 pcx. allow_similar_names = true ;
16381659 pcx. assemble_inherent_candidates ( ) ;
0 commit comments