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``
This commit is contained in:
Matthias Krüger 2024-04-13 16:42:06 +02:00 committed by GitHub
commit 3fb529e726
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -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;

View File

@ -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];