Skip to content

Commit

Permalink
dont fail when validating non-local closures
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Oct 9, 2018
1 parent 6899af8 commit 976880a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
bug!("Unexpected unsized type tail: {:?}", tail),
}
}
// for safe ptrs, recursively check
// for safe ptrs, also check the ptr values itself
if !ty.is_unsafe_ptr() {
// Make sure this is non-NULL and aligned
let (size, align) = self.size_and_align_of(place.extra, place.layout)?;
Expand Down Expand Up @@ -556,9 +556,13 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
match layout.ty.sty {
// generators and closures.
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
let freevar = self.tcx.with_freevars(node_id, |fv| fv[field]);
PathElem::ClosureVar(self.tcx.hir.name(freevar.var_id()))
if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
let freevar = self.tcx.with_freevars(node_id, |fv| fv[field]);
PathElem::ClosureVar(self.tcx.hir.name(freevar.var_id()))
} else {
// The closure is not local, so we cannot get the name
PathElem::ClosureVar(Symbol::intern(&field.to_string()))
}
}

// tuples
Expand Down

0 comments on commit 976880a

Please sign in to comment.