aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_fmt/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_fmt/src')
-rw-r--r--crates/ra_fmt/src/lib.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/crates/ra_fmt/src/lib.rs b/crates/ra_fmt/src/lib.rs
index 10f592257..4bca27b5c 100644
--- a/crates/ra_fmt/src/lib.rs
+++ b/crates/ra_fmt/src/lib.rs
@@ -35,8 +35,14 @@ fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> {
35 successors(token.prev_token(), |token| token.prev_token()) 35 successors(token.prev_token(), |token| token.prev_token())
36} 36}
37 37
38pub fn extract_trivial_expression(expr: &ast::BlockExpr) -> Option<ast::Expr> { 38pub fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr {
39 let block = expr.block()?; 39 extract_trivial_expression(&block)
40 .filter(|expr| !expr.syntax().text().contains_char('\n'))
41 .unwrap_or_else(|| block.into())
42}
43
44pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> {
45 let block = block.block()?;
40 let expr = block.expr()?; 46 let expr = block.expr()?;
41 let non_trivial_children = block.syntax().children().filter(|it| match it.kind() { 47 let non_trivial_children = block.syntax().children().filter(|it| match it.kind() {
42 WHITESPACE | T!['{'] | T!['}'] => false, 48 WHITESPACE | T!['{'] | T!['}'] => false,