Description
Right now, saved locals in generators are special-cased in miri, because they might not always be initialized.
With #59897 and #60187, we have the framework to fix this: fields are now only put in generator variants where they are live. The problem remains with aggregate fields, however, e.g.
fn gen() {
let x: (i32, i32);
x.0 = 5;
yield;
dbg!(x.0);
}
In this case x.1
is never initialized. This still presents a special case, because we cannot have a partially-unitialized field in a regular struct or enum type.
One way to remove the special-casing in miri is to wrap the type of every generator field in MaybeUninitialized
when we return it from rustc::ty::layout::field()
. This required making MaybeUnitialized
a lang item, though, and doesn't actually give us any new features.
Eventually, I think we'd like to handle aggregate fields explicitly, so we can sanitize UB in generators.