@@ -41,6 +41,7 @@ use rustc_trait_selection::traits::query::method_autoderef::{
41
41
use rustc_trait_selection:: traits:: query:: CanonicalTyGoal ;
42
42
use rustc_trait_selection:: traits:: ObligationCtxt ;
43
43
use rustc_trait_selection:: traits:: { self , ObligationCause } ;
44
+ use std:: cell:: Cell ;
44
45
use std:: cell:: RefCell ;
45
46
use std:: cmp:: max;
46
47
use std:: iter;
@@ -76,8 +77,12 @@ pub(crate) struct ProbeContext<'a, 'tcx> {
76
77
/// requested name (by edit distance)
77
78
allow_similar_names : bool ,
78
79
80
+ /// List of potential private candidates. Will be trimmed to ones that
81
+ /// actually apply and then the result inserted into `private_candidate`
82
+ private_candidates : Vec < Candidate < ' tcx > > ,
83
+
79
84
/// Some(candidate) if there is a private candidate
80
- private_candidate : Option < ( DefKind , DefId ) > ,
85
+ private_candidate : Cell < Option < ( DefKind , DefId ) > > ,
81
86
82
87
/// Collects near misses when the candidate functions are missing a `self` keyword and is only
83
88
/// used for error reporting
@@ -581,7 +586,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
581
586
orig_steps_var_values,
582
587
steps,
583
588
allow_similar_names : false ,
584
- private_candidate : None ,
589
+ private_candidates : Vec :: new ( ) ,
590
+ private_candidate : Cell :: new ( None ) ,
585
591
static_candidates : RefCell :: new ( Vec :: new ( ) ) ,
586
592
unsatisfied_predicates : RefCell :: new ( Vec :: new ( ) ) ,
587
593
scope_expr_id,
@@ -593,7 +599,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
593
599
self . inherent_candidates . clear ( ) ;
594
600
self . extension_candidates . clear ( ) ;
595
601
self . impl_dups . clear ( ) ;
596
- self . private_candidate = None ;
602
+ self . private_candidates . clear ( ) ;
603
+ self . private_candidate . set ( None ) ;
597
604
self . static_candidates . borrow_mut ( ) . clear ( ) ;
598
605
self . unsatisfied_predicates . borrow_mut ( ) . clear ( ) ;
599
606
}
@@ -617,9 +624,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
617
624
} else {
618
625
self . extension_candidates . push ( candidate) ;
619
626
}
620
- } else if self . private_candidate . is_none ( ) {
621
- self . private_candidate =
622
- Some ( ( candidate. item . kind . as_def_kind ( ) , candidate. item . def_id ) ) ;
627
+ } else {
628
+ self . private_candidates . push ( candidate) ;
623
629
}
624
630
}
625
631
@@ -1171,7 +1177,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1171
1177
let mut possibly_unsatisfied_predicates = Vec :: new ( ) ;
1172
1178
1173
1179
for ( kind, candidates) in
1174
- & [ ( "inherent" , & self . inherent_candidates ) , ( "extension" , & self . extension_candidates ) ]
1180
+ [ ( "inherent" , & self . inherent_candidates ) , ( "extension" , & self . extension_candidates ) ]
1175
1181
{
1176
1182
debug ! ( "searching {} candidates" , kind) ;
1177
1183
let res = self . consider_candidates (
@@ -1185,6 +1191,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1185
1191
}
1186
1192
}
1187
1193
1194
+ if self . private_candidate . get ( ) . is_none ( ) {
1195
+ if let Some ( Ok ( pick) ) =
1196
+ self . consider_candidates ( self_ty, & self . private_candidates , & mut vec ! [ ] , None )
1197
+ {
1198
+ self . private_candidate . set ( Some ( ( pick. item . kind . as_def_kind ( ) , pick. item . def_id ) ) ) ;
1199
+ }
1200
+ }
1201
+
1188
1202
// `pick_method` may be called twice for the same self_ty if no stable methods
1189
1203
// match. Only extend once.
1190
1204
if unstable_candidates. is_some ( ) {
0 commit comments