@@ -19,6 +19,7 @@ use rustc_hir::def_id::DefId;
19
19
use rustc_index:: vec:: Idx ;
20
20
use rustc_macros:: HashStable ;
21
21
use rustc_span:: symbol:: { kw, Ident , Symbol } ;
22
+ use rustc_span:: DUMMY_SP ;
22
23
use rustc_target:: abi:: VariantIdx ;
23
24
use rustc_target:: spec:: abi;
24
25
use std:: borrow:: Cow ;
@@ -672,22 +673,34 @@ pub enum ExistentialPredicate<'tcx> {
672
673
impl < ' tcx > ExistentialPredicate < ' tcx > {
673
674
/// Compares via an ordering that will not change if modules are reordered or other changes are
674
675
/// made to the tree. In particular, this ordering is preserved across incremental compilations.
675
- pub fn stable_cmp ( & self , tcx : TyCtxt < ' tcx > , other : & Self ) -> Ordering {
676
+ pub fn stable_cmp ( self , tcx : TyCtxt < ' tcx > , other : Self ) -> Ordering {
676
677
use self :: ExistentialPredicate :: * ;
677
678
// Note that we only call this method after checking that the
678
679
// given predicates represent a valid trait object.
679
680
//
680
681
// This means that we have at most one `ExistentialPredicate::Trait`
681
682
// and at most one `ExistentialPredicate::Projection` for each associated item.
682
- // We therefore do not have to worry about the ordering for cases which
683
- // are not well formed.
684
- match ( * self , * other) {
685
- ( Trait ( _) , Trait ( _) ) => Ordering :: Equal ,
686
- ( Projection ( ref a) , Projection ( ref b) ) => {
683
+ match ( self , other) {
684
+ ( Trait ( a) , Trait ( b) ) => {
685
+ if a != b {
686
+ tcx. sess . delay_span_bug (
687
+ DUMMY_SP ,
688
+ & format ! ( "unexpected existential predicates: {:?}, {:?}" , a, b) ,
689
+ ) ;
690
+ }
691
+ Ordering :: Equal
692
+ }
693
+ ( Projection ( a) , Projection ( b) ) => {
694
+ if a. item_def_id == b. item_def_id && a != b {
695
+ tcx. sess . delay_span_bug (
696
+ DUMMY_SP ,
697
+ & format ! ( "unexpected existential predicates: {:?}, {:?}" , a, b) ,
698
+ ) ;
699
+ }
687
700
tcx. def_path_hash ( a. item_def_id ) . cmp ( & tcx. def_path_hash ( b. item_def_id ) )
688
701
}
689
- ( AutoTrait ( ref a) , AutoTrait ( ref b) ) => {
690
- tcx. trait_def ( * a) . def_path_hash . cmp ( & tcx. trait_def ( * b) . def_path_hash )
702
+ ( AutoTrait ( a) , AutoTrait ( b) ) => {
703
+ tcx. trait_def ( a) . def_path_hash . cmp ( & tcx. trait_def ( b) . def_path_hash )
691
704
}
692
705
( Trait ( _) , _) => Ordering :: Less ,
693
706
( Projection ( _) , Trait ( _) ) => Ordering :: Greater ,
0 commit comments