@@ -581,17 +581,24 @@ fn object_ty_for_trait<'tcx>(
581
581
} ) ;
582
582
debug ! ( ?trait_predicate) ;
583
583
584
- let elaborated_predicates = elaborate_trait_ref ( tcx, trait_ref) . filter_map ( |obligation| {
585
- debug ! ( ?obligation) ;
586
- let pred = obligation. predicate . to_opt_poly_projection_pred ( ) ?;
587
- Some ( pred. map_bound ( |p| {
588
- ty:: ExistentialPredicate :: Projection ( ty:: ExistentialProjection {
589
- item_def_id : p. projection_ty . item_def_id ,
590
- substs : p. projection_ty . substs ,
591
- term : p. term ,
592
- } )
593
- } ) )
594
- } ) ;
584
+ let mut elaborated_predicates: Vec < _ > = elaborate_trait_ref ( tcx, trait_ref)
585
+ . filter_map ( |obligation| {
586
+ debug ! ( ?obligation) ;
587
+ let pred = obligation. predicate . to_opt_poly_projection_pred ( ) ?;
588
+ Some ( pred. map_bound ( |p| {
589
+ ty:: ExistentialPredicate :: Projection ( ty:: ExistentialProjection {
590
+ item_def_id : p. projection_ty . item_def_id ,
591
+ substs : p. projection_ty . substs ,
592
+ term : p. term ,
593
+ } )
594
+ } ) )
595
+ } )
596
+ . collect ( ) ;
597
+ // NOTE: Since #37965, the existential predicates list has depended on the
598
+ // list of predicates to be sorted. This is mostly to enforce that the primary
599
+ // predicate comes first.
600
+ elaborated_predicates. sort_by ( |a, b| a. skip_binder ( ) . stable_cmp ( tcx, & b. skip_binder ( ) ) ) ;
601
+ elaborated_predicates. dedup ( ) ;
595
602
596
603
let existential_predicates = tcx
597
604
. mk_poly_existential_predicates ( iter:: once ( trait_predicate) . chain ( elaborated_predicates) ) ;
0 commit comments