@@ -137,6 +137,18 @@ impl<'tcx> InferCtxt<'tcx> {
137
137
Err ( TypeError :: Sorts ( ty:: relate:: expected_found ( relation, a, b) ) )
138
138
}
139
139
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
+
140
152
_ => ty:: relate:: super_relate_tys ( relation, a, b) ,
141
153
}
142
154
}
@@ -505,10 +517,6 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
505
517
Obligation :: new ( self . infcx . tcx , self . trace . cause . clone ( ) , self . param_env , to_pred)
506
518
} ) )
507
519
}
508
-
509
- pub fn mark_ambiguous ( & mut self ) {
510
- self . register_predicates ( [ ty:: Binder :: dummy ( ty:: PredicateKind :: Ambiguous ) ] ) ;
511
- }
512
520
}
513
521
514
522
struct Generalizer < ' cx , ' tcx > {
@@ -581,10 +589,6 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
581
589
self . infcx . tcx
582
590
}
583
591
584
- fn intercrate ( & self ) -> bool {
585
- self . infcx . intercrate
586
- }
587
-
588
592
fn param_env ( & self ) -> ty:: ParamEnv < ' tcx > {
589
593
self . param_env
590
594
}
@@ -597,10 +601,6 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
597
601
true
598
602
}
599
603
600
- fn mark_ambiguous ( & mut self ) {
601
- span_bug ! ( self . cause. span, "opaque types are handled in `tys`" ) ;
602
- }
603
-
604
604
fn binders < T > (
605
605
& mut self ,
606
606
a : ty:: Binder < ' tcx , T > ,
0 commit comments