Preserve unsafe blocks in closures

Fixes #321
This commit is contained in:
Nick Cameron 2015-09-15 17:45:54 +12:00
parent ff02953a02
commit e4cca21a10
2 changed files with 4 additions and 1 deletions

View File

@ -280,7 +280,9 @@ fn rewrite_closure(capture: ast::CaptureClause,
// All closure bodies are blocks in the eyes of the AST, but we may not
// want to unwrap them when they only contain a single expression.
let inner_expr = match expr.node {
ast::Expr_::ExprBlock(ref inner) if inner.stmts.is_empty() && inner.expr.is_some() => {
ast::Expr_::ExprBlock(ref inner) if inner.stmts.is_empty() && inner.expr.is_some() &&
inner.rules ==
ast::BlockCheckMode::DefaultBlock => {
inner.expr.as_ref().unwrap()
}
_ => expr,

View File

@ -82,4 +82,5 @@ fn homura<T: Deref<Target = i32>>(_: T) {
fn main() {
let _ = function(move || 5);
let _ = move || 42;
let _ = || unsafe { abort() };
}