Skip to content

Commit f095562

Browse files
committed
Handle closures in get_field_ty
Fixes #304
1 parent 5d60c61 commit f095562

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/librustc_mir/interpret/eval_context.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,11 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
11441144
packed: false,
11451145
}),
11461146

1147+
ty::TyClosure(def_id, ref closure_substs) => Ok(TyAndPacked {
1148+
ty: closure_substs.upvar_tys(def_id, self.tcx).nth(field_index).unwrap(),
1149+
packed: false,
1150+
}),
1151+
11471152
_ => {
11481153
err!(Unimplemented(
11491154
format!("can't handle type: {:?}, {:?}", ty, ty.sty),

tests/run-pass/closure-field-ty.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// miri issue #304
2+
fn main() {
3+
let mut y = 0;
4+
{
5+
let mut box_maybe_closure = Box::new(None);
6+
*box_maybe_closure = Some(|| { y += 1; });
7+
(box_maybe_closure.unwrap())();
8+
}
9+
assert_eq!(y, 1);
10+
}

0 commit comments

Comments
 (0)