mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
fix panic on closure with empty block expr (#3846)
This commit is contained in:
parent
6dcbc5d78e
commit
207a58f365
@ -91,8 +91,9 @@ fn get_inner_expr<'a>(
|
||||
) -> &'a ast::Expr {
|
||||
if let ast::ExprKind::Block(ref block, _) = expr.kind {
|
||||
if !needs_block(block, prefix, context) {
|
||||
// block.stmts.len() == 1
|
||||
if let Some(expr) = stmt_expr(&block.stmts[0]) {
|
||||
// block.stmts.len() == 1 except with `|| {{}}`;
|
||||
// https://github.com/rust-lang/rustfmt/issues/3844
|
||||
if let Some(expr) = block.stmts.first().and_then(stmt_expr) {
|
||||
return get_inner_expr(expr, prefix, context);
|
||||
}
|
||||
}
|
||||
|
3
tests/source/issue_3844.rs
Normal file
3
tests/source/issue_3844.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
|| {{}};
|
||||
}
|
3
tests/target/issue_3844.rs
Normal file
3
tests/target/issue_3844.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
|| {};
|
||||
}
|
Loading…
Reference in New Issue
Block a user