@@ -4,7 +4,7 @@ use rustc_type_ir::data_structures::IndexSet;
44use rustc_type_ir:: fast_reject:: DeepRejectCtxt ;
55use rustc_type_ir:: inherent:: * ;
66use rustc_type_ir:: lang_items:: SolverTraitLangItem ;
7- use rustc_type_ir:: solve:: { CanonicalResponse , SizedTraitKind } ;
7+ use rustc_type_ir:: solve:: { CandidatePreferenceMode , CanonicalResponse , SizedTraitKind } ;
88use rustc_type_ir:: {
99 self as ty, Interner , Movability , PredicatePolarity , TraitPredicate , TraitRef ,
1010 TypeVisitableExt as _, TypingMode , Upcast as _, elaborate,
@@ -1355,6 +1355,7 @@ where
13551355 #[ instrument( level = "debug" , skip( self ) , ret) ]
13561356 pub ( super ) fn merge_trait_candidates (
13571357 & mut self ,
1358+ candidate_preference_mode : CandidatePreferenceMode ,
13581359 mut candidates : Vec < Candidate < I > > ,
13591360 failed_candidate_info : FailedCandidateInfo ,
13601361 ) -> Result < ( CanonicalResponse < I > , Option < TraitGoalProvenVia > ) , NoSolution > {
@@ -1380,6 +1381,24 @@ where
13801381 return Ok ( ( candidate. result , Some ( TraitGoalProvenVia :: Misc ) ) ) ;
13811382 }
13821383
1384+ let potential_alias_bound_response =
1385+ candidates. iter ( ) . any ( |c| matches ! ( c. source, CandidateSource :: AliasBound ) ) . then ( || {
1386+ let alias_bounds: Vec < _ > = candidates
1387+ . extract_if ( .., |c| matches ! ( c. source, CandidateSource :: AliasBound ) )
1388+ . collect ( ) ;
1389+ if let Some ( ( response, _) ) = self . try_merge_candidates ( & alias_bounds) {
1390+ ( response, Some ( TraitGoalProvenVia :: AliasBound ) )
1391+ } else {
1392+ ( self . bail_with_ambiguity ( & alias_bounds) , None )
1393+ }
1394+ } ) ;
1395+
1396+ if matches ! ( candidate_preference_mode, CandidatePreferenceMode :: Marker )
1397+ && let Some ( alias_bound_response) = potential_alias_bound_response
1398+ {
1399+ return Ok ( alias_bound_response) ;
1400+ }
1401+
13831402 // If there are non-global where-bounds, prefer where-bounds
13841403 // (including global ones) over everything else.
13851404 let has_non_global_where_bounds = candidates
@@ -1427,15 +1446,8 @@ where
14271446 } ;
14281447 }
14291448
1430- if candidates. iter ( ) . any ( |c| matches ! ( c. source, CandidateSource :: AliasBound ) ) {
1431- let alias_bounds: Vec < _ > = candidates
1432- . extract_if ( .., |c| matches ! ( c. source, CandidateSource :: AliasBound ) )
1433- . collect ( ) ;
1434- return if let Some ( ( response, _) ) = self . try_merge_candidates ( & alias_bounds) {
1435- Ok ( ( response, Some ( TraitGoalProvenVia :: AliasBound ) ) )
1436- } else {
1437- Ok ( ( self . bail_with_ambiguity ( & alias_bounds) , None ) )
1438- } ;
1449+ if let Some ( response) = potential_alias_bound_response {
1450+ return Ok ( response) ;
14391451 }
14401452
14411453 self . filter_specialized_impls ( AllowInferenceConstraints :: No , & mut candidates) ;
@@ -1470,7 +1482,9 @@ where
14701482 ) -> Result < ( CanonicalResponse < I > , Option < TraitGoalProvenVia > ) , NoSolution > {
14711483 let ( candidates, failed_candidate_info) =
14721484 self . assemble_and_evaluate_candidates ( goal, AssembleCandidatesFrom :: All ) ;
1473- self . merge_trait_candidates ( candidates, failed_candidate_info)
1485+ let candidate_preference_mode =
1486+ CandidatePreferenceMode :: compute ( self . cx ( ) , goal. predicate . def_id ( ) ) ;
1487+ self . merge_trait_candidates ( candidate_preference_mode, candidates, failed_candidate_info)
14741488 }
14751489
14761490 fn try_stall_coroutine ( & mut self , self_ty : I :: Ty ) -> Option < Result < Candidate < I > , NoSolution > > {
0 commit comments