Skip to content

Commit 6befe67

Browse files
committed
treat generator fields like unions
1 parent 7f10777 commit 6befe67

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/librustc_mir/interpret/visitor.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ macro_rules! make_value_visitor {
158158
) -> EvalResult<'tcx> {
159159
self.walk_aggregate(v, fields)
160160
}
161-
/// Called each time we recurse down to a field, passing in old and new value.
161+
162+
/// Called each time we recurse down to a field of a "product-like" aggregate
163+
/// (structs, tuples, arrays and the like, but not enums), passing in old and new value.
162164
/// This gives the visitor the chance to track the stack of nested fields that
163165
/// we are descending through.
164166
#[inline(always)]
@@ -171,6 +173,19 @@ macro_rules! make_value_visitor {
171173
self.visit_value(new_val)
172174
}
173175

176+
/// Called for recursing into the field of a generator. These are not known to be
177+
/// initialized, so we treat them like unions.
178+
#[inline(always)]
179+
fn visit_generator_field(
180+
&mut self,
181+
_old_val: Self::V,
182+
_field: usize,
183+
new_val: Self::V,
184+
) -> EvalResult<'tcx> {
185+
self.visit_union(new_val)
186+
}
187+
188+
/// Called when recursing into an enum variant.
174189
#[inline(always)]
175190
fn visit_variant(
176191
&mut self,
@@ -300,7 +315,12 @@ macro_rules! make_value_visitor {
300315
match v.layout().ty.sty {
301316
ty::Generator(..) => {
302317
let field = v.project_field(self.ecx(), 0)?;
303-
self.visit_aggregate(v, std::iter::once(Ok(field)))
318+
self.visit_aggregate(v, std::iter::once(Ok(field)))?;
319+
for i in 1..offsets.len() {
320+
let field = v.project_field(self.ecx(), i as u64)?;
321+
self.visit_generator_field(v, i, field)?;
322+
}
323+
Ok(())
304324
}
305325
_ => {
306326
// FIXME: We collect in a vec because otherwise there are lifetime

0 commit comments

Comments
 (0)