@@ -137,6 +137,18 @@ impl<'tcx> InferCtxt<'tcx> {
137137 Err ( TypeError :: Sorts ( ty:: relate:: expected_found ( relation, a, b) ) )
138138 }
139139
140+ // During coherence, opaque types should be treated as *possibly*
141+ // equal to each other, even if their generic params differ, as
142+ // they could resolve to the same hidden type, even for different
143+ // generic params.
144+ (
145+ & ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id : a_def_id, .. } ) ,
146+ & ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id : b_def_id, .. } ) ,
147+ ) if self . intercrate && a_def_id == b_def_id => {
148+ relation. register_predicates ( [ ty:: Binder :: dummy ( ty:: PredicateKind :: Ambiguous ) ] ) ;
149+ Ok ( a)
150+ }
151+
140152 _ => ty:: relate:: super_relate_tys ( relation, a, b) ,
141153 }
142154 }
@@ -505,10 +517,6 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
505517 Obligation :: new ( self . infcx . tcx , self . trace . cause . clone ( ) , self . param_env , to_pred)
506518 } ) )
507519 }
508-
509- pub fn mark_ambiguous ( & mut self ) {
510- self . register_predicates ( [ ty:: Binder :: dummy ( ty:: PredicateKind :: Ambiguous ) ] ) ;
511- }
512520}
513521
514522struct Generalizer < ' cx , ' tcx > {
@@ -581,10 +589,6 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
581589 self . infcx . tcx
582590 }
583591
584- fn intercrate ( & self ) -> bool {
585- self . infcx . intercrate
586- }
587-
588592 fn param_env ( & self ) -> ty:: ParamEnv < ' tcx > {
589593 self . param_env
590594 }
@@ -597,10 +601,6 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
597601 true
598602 }
599603
600- fn mark_ambiguous ( & mut self ) {
601- span_bug ! ( self . cause. span, "opaque types are handled in `tys`" ) ;
602- }
603-
604604 fn binders < T > (
605605 & mut self ,
606606 a : ty:: Binder < ' tcx , T > ,
0 commit comments