Skip to content

Commit 976880a

Browse files
committed
dont fail when validating non-local closures
1 parent 6899af8 commit 976880a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/librustc_mir/interpret/validity.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
207207
bug!("Unexpected unsized type tail: {:?}", tail),
208208
}
209209
}
210-
// for safe ptrs, recursively check
210+
// for safe ptrs, also check the ptr values itself
211211
if !ty.is_unsafe_ptr() {
212212
// Make sure this is non-NULL and aligned
213213
let (size, align) = self.size_and_align_of(place.extra, place.layout)?;
@@ -556,9 +556,13 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
556556
match layout.ty.sty {
557557
// generators and closures.
558558
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
559-
let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
560-
let freevar = self.tcx.with_freevars(node_id, |fv| fv[field]);
561-
PathElem::ClosureVar(self.tcx.hir.name(freevar.var_id()))
559+
if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
560+
let freevar = self.tcx.with_freevars(node_id, |fv| fv[field]);
561+
PathElem::ClosureVar(self.tcx.hir.name(freevar.var_id()))
562+
} else {
563+
// The closure is not local, so we cannot get the name
564+
PathElem::ClosureVar(Symbol::intern(&field.to_string()))
565+
}
562566
}
563567

564568
// tuples

0 commit comments

Comments
 (0)