@@ -27,6 +27,7 @@ use crate::infer::{ConstVarValue, ConstVariableValue};
27
27
use crate :: infer:: { TypeVariableOrigin , TypeVariableOriginKind } ;
28
28
use crate :: traits:: { Obligation , PredicateObligation } ;
29
29
use rustc_data_structures:: fx:: FxHashMap ;
30
+ use rustc_hir:: def:: DefKind ;
30
31
use rustc_middle:: traits:: ObligationCause ;
31
32
use rustc_middle:: ty:: error:: TypeError ;
32
33
use rustc_middle:: ty:: relate:: { self , Relate , RelateResult , TypeRelation } ;
@@ -410,7 +411,7 @@ where
410
411
let ( a, b) = match ( a. kind ( ) , b. kind ( ) ) {
411
412
( & ty:: Alias ( ty:: Opaque , ..) , _) => ( a, generalize ( b, false ) ?) ,
412
413
( _, & ty:: Alias ( ty:: Opaque , ..) ) => ( generalize ( a, true ) ?, b) ,
413
- _ => unreachable ! ( ) ,
414
+ _ => unreachable ! ( "expected an opaque, got {a} and {b}" ) ,
414
415
} ;
415
416
let cause = ObligationCause :: dummy_with_span ( self . delegate . span ( ) ) ;
416
417
let obligations = self
@@ -627,6 +628,42 @@ where
627
628
self . relate_opaques ( a, b)
628
629
}
629
630
631
+ // Handle default-body RPITITs
632
+ (
633
+ & ty:: Alias ( ty:: Projection , ty:: AliasTy { def_id : a_def_id, .. } ) ,
634
+ & ty:: Alias ( ty:: Projection , ty:: AliasTy { def_id : b_def_id, .. } ) ,
635
+ ) if a_def_id == b_def_id
636
+ && self . tcx ( ) . def_kind ( a_def_id) == DefKind :: ImplTraitPlaceholder
637
+ && a_def_id. as_local ( ) . map_or ( false , |def_id| {
638
+ self . infcx . opaque_type_origin ( def_id, self . delegate . span ( ) ) . is_some ( )
639
+ } ) =>
640
+ {
641
+ infcx. super_combine_tys ( self , a, b) . or_else ( |err| {
642
+ self . tcx ( ) . sess . delay_span_bug (
643
+ self . delegate . span ( ) ,
644
+ "failure to relate an opaque to itself should result in an error later on" ,
645
+ ) ;
646
+ if a_def_id. is_local ( ) { self . relate_opaques ( a, b) } else { Err ( err) }
647
+ } )
648
+ }
649
+ ( & ty:: Alias ( ty:: Projection , ty:: AliasTy { def_id, substs, .. } ) , _)
650
+ if self . tcx ( ) . def_kind ( def_id) == DefKind :: ImplTraitPlaceholder
651
+ && def_id. as_local ( ) . map_or ( false , |def_id| {
652
+ self . infcx . opaque_type_origin ( def_id, self . delegate . span ( ) ) . is_some ( )
653
+ } ) =>
654
+ {
655
+ self . relate_opaques ( self . tcx ( ) . mk_opaque ( def_id, substs) , b)
656
+ }
657
+
658
+ ( _, & ty:: Alias ( ty:: Projection , ty:: AliasTy { def_id, substs, .. } ) )
659
+ if self . tcx ( ) . def_kind ( def_id) == DefKind :: ImplTraitPlaceholder
660
+ && def_id. as_local ( ) . map_or ( false , |def_id| {
661
+ self . infcx . opaque_type_origin ( def_id, self . delegate . span ( ) ) . is_some ( )
662
+ } ) =>
663
+ {
664
+ self . relate_opaques ( a, self . tcx ( ) . mk_opaque ( def_id, substs) )
665
+ }
666
+
630
667
( & ty:: Alias ( ty:: Projection , projection_ty) , _)
631
668
if D :: normalization ( ) == NormalizationStrategy :: Lazy =>
632
669
{
0 commit comments