diff options
Diffstat (limited to 'crates/ra_fmt')
-rw-r--r-- | crates/ra_fmt/src/lib.rs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/crates/ra_fmt/src/lib.rs b/crates/ra_fmt/src/lib.rs index 0b4ba1bbe..f910ded9d 100644 --- a/crates/ra_fmt/src/lib.rs +++ b/crates/ra_fmt/src/lib.rs | |||
@@ -42,7 +42,6 @@ pub fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr { | |||
42 | } | 42 | } |
43 | 43 | ||
44 | pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> { | 44 | pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> { |
45 | let block = block.block()?; | ||
46 | let has_anything_else = |thing: &SyntaxNode| -> bool { | 45 | let has_anything_else = |thing: &SyntaxNode| -> bool { |
47 | let mut non_trivial_children = | 46 | let mut non_trivial_children = |
48 | block.syntax().children_with_tokens().filter(|it| match it.kind() { | 47 | block.syntax().children_with_tokens().filter(|it| match it.kind() { |
@@ -57,18 +56,17 @@ pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> { | |||
57 | return None; | 56 | return None; |
58 | } | 57 | } |
59 | return Some(expr); | 58 | return Some(expr); |
60 | } else { | 59 | } |
61 | // Unwrap `{ continue; }` | 60 | // Unwrap `{ continue; }` |
62 | let (stmt,) = block.statements().next_tuple()?; | 61 | let (stmt,) = block.statements().next_tuple()?; |
63 | if let ast::Stmt::ExprStmt(expr_stmt) = stmt { | 62 | if let ast::Stmt::ExprStmt(expr_stmt) = stmt { |
64 | if has_anything_else(expr_stmt.syntax()) { | 63 | if has_anything_else(expr_stmt.syntax()) { |
65 | return None; | 64 | return None; |
66 | } | 65 | } |
67 | let expr = expr_stmt.expr()?; | 66 | let expr = expr_stmt.expr()?; |
68 | match expr.syntax().kind() { | 67 | match expr.syntax().kind() { |
69 | CONTINUE_EXPR | BREAK_EXPR | RETURN_EXPR => return Some(expr), | 68 | CONTINUE_EXPR | BREAK_EXPR | RETURN_EXPR => return Some(expr), |
70 | _ => (), | 69 | _ => (), |
71 | } | ||
72 | } | 70 | } |
73 | } | 71 | } |
74 | None | 72 | None |