Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle closures in get_field_ty #306

Merged
merged 1 commit into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}