about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-04-13 16:42:06 +0200
committerGitHub <noreply@github.com>2024-04-13 16:42:06 +0200
commit3fb529e726f1ae66dcafb5ab5c91e85892af943e (patch)
tree76648cea68d015287027c74d2fe32e62da87a2b5
parent360f9ed5734ed8bcaac1f56311c92697bbe5f3d3 (diff)
parentc6a4f810d926d00a176de40ae78288c145f3843d (diff)
downloadrust-3fb529e726f1ae66dcafb5ab5c91e85892af943e.tar.gz
rust-3fb529e726f1ae66dcafb5ab5c91e85892af943e.zip
Rollup merge of #123888 - oli-obk:define_opaque_types4, r=compiler-errors
Replace a `DefiningOpaqueTypes::No` with `Yes` by asserting that one side of the comparison is a type variable.

Thus there will never be an opaque type involved in a way that constrains its hidden type, as the other side of the comparison is always a generator witness type

r? ``@compiler-errors``
-rw-r--r--compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs6
-rw-r--r--compiler/rustc_type_ir/src/ty_kind.rs4
2 files changed, 7 insertions, 3 deletions
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
index da46ed07690..2580179ce5b 100644
--- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
+++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
@@ -561,9 +561,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
 
             // Unify `interior` with `witness` and collect all the resulting obligations.
             let span = self.tcx.hir().body(body_id).value.span;
+            let ty::Infer(ty::InferTy::TyVar(_)) = interior.kind() else {
+                span_bug!(span, "coroutine interior witness not infer: {:?}", interior.kind())
+            };
             let ok = self
                 .at(&self.misc(span), self.param_env)
-                .eq(DefineOpaqueTypes::No, interior, witness)
+                // Will never define opaque types, as all we do is instantiate a type variable.
+                .eq(DefineOpaqueTypes::Yes, interior, witness)
                 .expect("Failed to unify coroutine interior type");
             let mut obligations = ok.obligations;
 
diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs
index 56ae7ad9f74..397e104512f 100644
--- a/compiler/rustc_type_ir/src/ty_kind.rs
+++ b/compiler/rustc_type_ir/src/ty_kind.rs
@@ -181,9 +181,9 @@ pub enum TyKind<I: Interner> {
     /// Looking at the following example, the witness for this coroutine
     /// may end up as something like `for<'a> [Vec<i32>, &'a Vec<i32>]`:
     ///
-    /// ```ignore UNSOLVED (ask @compiler-errors, should this error? can we just swap the yields?)
+    /// ```
     /// #![feature(coroutines)]
-    /// |a| {
+    /// static |a| {
     ///     let x = &vec![3];
     ///     yield a;
     ///     yield x[0];