Skip to content

Commit c16a90f

Browse files
committed
Test generalization during coherence
1 parent 11adf03 commit c16a90f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

compiler/rustc_infer/src/infer/combine.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
548548
}
549549

550550
fn mark_ambiguous(&mut self) {
551-
self.infcx.tcx.sess.delay_span_bug(self.cause.span, "we only generalize opaque types in situations where we already error for them elsewhere in coherence");
551+
span_bug!(self.cause.span, "opaque types are handled in `tys`");
552552
}
553553

554554
fn binders<T>(
@@ -675,6 +675,10 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
675675
// relatable.
676676
Ok(t)
677677
}
678+
ty::Opaque(def_id, substs) => {
679+
let s = self.relate(substs, substs)?;
680+
Ok(if s == substs { t } else { self.infcx.tcx.mk_opaque(def_id, s) })
681+
}
678682
_ => relate::super_relate_tys(self, t, t),
679683
}?;
680684

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
trait Trait {}
5+
type Opaque<T> = impl Sized;
6+
fn foo<T>() -> Opaque<T> {
7+
()
8+
}
9+
10+
impl<T, V> Trait for (T, V, V, u32) {}
11+
impl<U, V> Trait for (Opaque<U>, V, i32, V) {}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)