Merge pull request #2172 from topecongiro/issue-2171

Do not squash unsafe block on closure body
This commit is contained in:
Nick Cameron 2017-11-21 07:07:12 +13:00 committed by GitHub
commit b4378a1919
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View file

@ -256,7 +256,9 @@ pub fn rewrite_last_closure(
) -> Option<String> {
if let ast::ExprKind::Closure(capture, ref fn_decl, ref body, _) = expr.node {
let body = match body.node {
ast::ExprKind::Block(ref block) if is_simple_block(block, context.codemap) => {
ast::ExprKind::Block(ref block)
if !is_unsafe_block(block) && is_simple_block(block, context.codemap) =>
{
stmt_expr(&block.stmts[0]).unwrap_or(body)
}
_ => body,

View file

@ -188,3 +188,13 @@ fn issue1524() {
let f = |x| {x};
let f = |x| x;
}
fn issue2171() {
foo(|| unsafe {
if PERIPHERALS {
loop {}
} else {
PERIPHERALS = true;
}
})
}

View file

@ -220,3 +220,13 @@ fn issue1524() {
let f = |x| x;
let f = |x| x;
}
fn issue2171() {
foo(|| unsafe {
if PERIPHERALS {
loop {}
} else {
PERIPHERALS = true;
}
})
}