Merge pull request #323 from nrc/unsafe-closure

Preserve unsafe blocks in closures
This commit is contained in:
Marcus Klaas de Vries 2015-09-16 20:02:30 +02:00
commit d4d8a8cc87
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() };
}