Skip to content

Commit

Permalink
Handle closures in get_field_ty
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 24, 2017
1 parent 3f3fada commit e332ab9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,11 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
packed: false,
}),

ty::TyClosure(def_id, ref closure_substs) => Ok(TyAndPacked {
ty: closure_substs.upvar_tys(def_id, self.tcx).nth(field_index).unwrap(),
packed: false,
}),

_ => {
err!(Unimplemented(
format!("can't handle type: {:?}, {:?}", ty, ty.sty),
Expand Down
10 changes: 10 additions & 0 deletions tests/run-pass/closure-field-ty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// miri issue #304
fn main() {
let mut y = 0;
{
let mut box_maybe_closure = Box::new(None);
*box_maybe_closure = Some(|| { y += 1; });
(box_maybe_closure.unwrap())();
}
assert_eq!(y, 1);
}

0 comments on commit e332ab9

Please sign in to comment.