@@ -289,9 +289,10 @@ where
289
289
D : SolverDelegate < Interner = I > ,
290
290
I : Interner ,
291
291
{
292
- pub ( super ) fn assemble_and_evaluate_candidates < G : GoalKind < D > > (
292
+ fn assemble_and_evaluate_candidates_with_normalized_goal < G : GoalKind < D > > (
293
293
& mut self ,
294
294
goal : Goal < I , G > ,
295
+ assemble : impl FnOnce ( & mut Self , Goal < I , G > ) -> Vec < Candidate < I > > ,
295
296
) -> Vec < Candidate < I > > {
296
297
let Ok ( normalized_self_ty) =
297
298
self . structurally_normalize_ty ( goal. param_env , goal. predicate . self_ty ( ) )
@@ -310,25 +311,40 @@ where
310
311
// normalizing the self type as well, since type variables are not uniquified.
311
312
let goal = self . resolve_vars_if_possible ( goal) ;
312
313
313
- let mut candidates = vec ! [ ] ;
314
-
315
314
if let TypingMode :: Coherence = self . typing_mode ( ) {
316
315
if let Ok ( candidate) = self . consider_coherence_unknowable_candidate ( goal) {
317
316
return vec ! [ candidate] ;
318
317
}
319
318
}
320
319
321
- self . assemble_impl_candidates ( goal, & mut candidates) ;
322
-
323
- self . assemble_builtin_impl_candidates ( goal, & mut candidates) ;
324
-
325
- self . assemble_alias_bound_candidates ( goal, & mut candidates) ;
326
-
327
- self . assemble_object_bound_candidates ( goal, & mut candidates) ;
320
+ assemble ( self , goal)
321
+ }
328
322
329
- self . assemble_param_env_candidates ( goal, & mut candidates) ;
323
+ pub ( super ) fn assemble_and_evaluate_candidates_from_env_and_bounds < G : GoalKind < D > > (
324
+ & mut self ,
325
+ goal : Goal < I , G > ,
326
+ ) -> Vec < Candidate < I > > {
327
+ self . assemble_and_evaluate_candidates_with_normalized_goal ( goal, |ecx, goal| {
328
+ let mut candidates = vec ! [ ] ;
329
+ ecx. assemble_alias_bound_candidates ( goal, & mut candidates) ;
330
+ ecx. assemble_param_env_candidates ( goal, & mut candidates) ;
331
+ candidates
332
+ } )
333
+ }
330
334
331
- candidates
335
+ pub ( super ) fn assemble_and_evaluate_candidates < G : GoalKind < D > > (
336
+ & mut self ,
337
+ goal : Goal < I , G > ,
338
+ ) -> Vec < Candidate < I > > {
339
+ self . assemble_and_evaluate_candidates_with_normalized_goal ( goal, |ecx, goal| {
340
+ let mut candidates = vec ! [ ] ;
341
+ ecx. assemble_impl_candidates ( goal, & mut candidates) ;
342
+ ecx. assemble_builtin_impl_candidates ( goal, & mut candidates) ;
343
+ ecx. assemble_alias_bound_candidates ( goal, & mut candidates) ;
344
+ ecx. assemble_object_bound_candidates ( goal, & mut candidates) ;
345
+ ecx. assemble_param_env_candidates ( goal, & mut candidates) ;
346
+ candidates
347
+ } )
332
348
}
333
349
334
350
pub ( super ) fn forced_ambiguity (
@@ -778,10 +794,10 @@ where
778
794
///
779
795
/// See trait-system-refactor-initiative#124 for more details.
780
796
#[ instrument( level = "debug" , skip( self , inject_normalize_to_rigid_candidate) , ret) ]
781
- pub ( super ) fn merge_candidates (
797
+ pub ( super ) fn assemble_and_merge_candidates < G : GoalKind < D > > (
782
798
& mut self ,
783
799
proven_via : Option < TraitGoalProvenVia > ,
784
- candidates : Vec < Candidate < I > > ,
800
+ goal : Goal < I , G > ,
785
801
inject_normalize_to_rigid_candidate : impl FnOnce ( & mut EvalCtxt < ' _ , D > ) -> QueryResult < I > ,
786
802
) -> QueryResult < I > {
787
803
let Some ( proven_via) = proven_via else {
@@ -800,15 +816,16 @@ where
800
816
// constness checking. Doing so is *at least theoretically* breaking,
801
817
// see github.com/rust-lang/rust/issues/133044#issuecomment-2500709754
802
818
TraitGoalProvenVia :: ParamEnv | TraitGoalProvenVia :: AliasBound => {
803
- let mut candidates_from_env_and_bounds: Vec < _ > = candidates
804
- . iter ( )
805
- . filter ( |c| {
806
- matches ! (
819
+ let mut candidates_from_env_and_bounds: Vec < _ > = self
820
+ . assemble_and_evaluate_candidates_from_env_and_bounds ( goal)
821
+ . into_iter ( )
822
+ . map ( |c| {
823
+ debug_assert ! ( matches!(
807
824
c. source,
808
825
CandidateSource :: AliasBound | CandidateSource :: ParamEnv ( _)
809
- )
826
+ ) ) ;
827
+ c. result
810
828
} )
811
- . map ( |c| c. result )
812
829
. collect ( ) ;
813
830
814
831
// If the trait goal has been proven by using the environment, we want to treat
@@ -826,6 +843,8 @@ where
826
843
}
827
844
}
828
845
TraitGoalProvenVia :: Misc => {
846
+ let candidates = self . assemble_and_evaluate_candidates ( goal) ;
847
+
829
848
// Prefer "orphaned" param-env normalization predicates, which are used
830
849
// (for example, and ideally only) when proving item bounds for an impl.
831
850
let candidates_from_env: Vec < _ > = candidates
0 commit comments