提交 321a72c1 编写于 作者: R Ralf Jung

closure unsafety check: stop moving up when we hit an item

上级 a8129d12
......@@ -128,29 +128,29 @@ fn fn_is_closure<'a>(fn_like: FnLikeNode<'a>) -> bool {
let mut cur = fn_like.id();
loop {
// Go further upwards.
let parent = tcx.hir.get_parent_node(cur);
if cur == parent {
bug!("Closures muts be inside a non-closure fn_like");
}
cur = parent;
// Check if this is an unsafe block
match tcx.hir.find(cur) {
Some(Node::NodeExpr(&hir::Expr { node: hir::ExprBlock(ref block), ..})) => {
if block_is_unsafe(&*block) {
// Found an unsafe block, we can bail out here.
cur = tcx.hir.get_parent_node(cur);
let node = tcx.hir.get(cur);
// Check if this is an unsafe function
if let Some(fn_like) = FnLikeNode::from_node(node) {
if !fn_is_closure(fn_like) {
if fn_like.unsafety() == hir::Unsafety::Unsafe {
return true;
}
}
_ => {},
}
// Check if this is a non-closure fn_like, at which point we have to stop moving up
if let Some(fn_like) = FnLikeNode::from_node(tcx.hir.get(cur)) {
if !fn_is_closure(fn_like) {
if fn_like.unsafety() == hir::Unsafety::Unsafe {
// Check if this is an unsafe block, or an item
match node {
Node::NodeExpr(&hir::Expr { node: hir::ExprBlock(ref block), ..}) => {
if block_is_unsafe(&*block) {
// Found an unsafe block, we can bail out here.
return true;
}
}
Node::NodeItem(..) => {
// No walking up beyond items. This makes sure the loop always terminates.
break;
}
_ => {},
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册