1
Fork 0

Rollup merge of #118871 - tmiasko:coroutine-maybe-uninit-fields, r=compiler-errors

Coroutine variant fields can be uninitialized

Wrap coroutine variant fields in MaybeUninit to indicate that they might be uninitialized. Otherwise an uninhabited field will make the entire variant uninhabited and introduce undefined behaviour.

The analogous issue in the prefix of coroutine layout was addressed by 6fae7f8071.
This commit is contained in:
Matthias Krüger 2023-12-13 18:03:33 +01:00 committed by GitHub
commit 1dd36119d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 4 deletions

View file

@ -831,7 +831,10 @@ fn coroutine_layout<'tcx>(
Assigned(_) => bug!("assignment does not match variant"),
Ineligible(_) => false,
})
.map(|local| subst_field(info.field_tys[*local].ty));
.map(|local| {
let field_ty = subst_field(info.field_tys[*local].ty);
Ty::new_maybe_uninit(tcx, field_ty)
});
let mut variant = univariant_uninterned(
cx,