about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-11-17 10:40:35 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-11-21 16:47:29 +0000
commitc16a90f5e3cb26b15e12c8d24d7b1cafbe90e24a (patch)
tree2477bf260e2e7127b4386cf237a80b5d12d35499
parent11adf037906fd918e0a77116db8c8b17e0fcee73 (diff)
downloadrust-c16a90f5e3cb26b15e12c8d24d7b1cafbe90e24a.tar.gz
rust-c16a90f5e3cb26b15e12c8d24d7b1cafbe90e24a.zip
Test generalization during coherence
-rw-r--r--compiler/rustc_infer/src/infer/combine.rs6
-rw-r--r--src/test/ui/type-alias-impl-trait/coherence_generalization.rs13
2 files changed, 18 insertions, 1 deletions
diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs
index 256a6dc47f4..eec938cefbb 100644
--- a/compiler/rustc_infer/src/infer/combine.rs
+++ b/compiler/rustc_infer/src/infer/combine.rs
@@ -548,7 +548,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
     }
 
     fn mark_ambiguous(&mut self) {
-        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");
+        span_bug!(self.cause.span, "opaque types are handled in `tys`");
     }
 
     fn binders<T>(
@@ -675,6 +675,10 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
                 // relatable.
                 Ok(t)
             }
+            ty::Opaque(def_id, substs) => {
+                let s = self.relate(substs, substs)?;
+                Ok(if s == substs { t } else { self.infcx.tcx.mk_opaque(def_id, s) })
+            }
             _ => relate::super_relate_tys(self, t, t),
         }?;
 
diff --git a/src/test/ui/type-alias-impl-trait/coherence_generalization.rs b/src/test/ui/type-alias-impl-trait/coherence_generalization.rs
new file mode 100644
index 00000000000..5c9ad9498b6
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/coherence_generalization.rs
@@ -0,0 +1,13 @@
+// check-pass
+
+#![feature(type_alias_impl_trait)]
+trait Trait {}
+type Opaque<T> = impl Sized;
+fn foo<T>() -> Opaque<T> {
+    ()
+}
+
+impl<T, V> Trait for (T, V, V, u32) {}
+impl<U, V> Trait for (Opaque<U>, V, i32, V) {}
+
+fn main() {}