From f0a9128761e8dd42f0dd40610a1d8734a52f3d9c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 11:41:20 +0200 Subject: Minor --- crates/ra_fmt/src/lib.rs | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) (limited to 'crates/ra_fmt/src') diff --git a/crates/ra_fmt/src/lib.rs b/crates/ra_fmt/src/lib.rs index 397a3c3ae..d0004654b 100644 --- a/crates/ra_fmt/src/lib.rs +++ b/crates/ra_fmt/src/lib.rs @@ -2,9 +2,8 @@ use std::iter::successors; -use itertools::Itertools; use syntax::{ - ast::{self, AstNode, AstToken}, + ast::{self, AstToken}, SmolStr, SyntaxKind, SyntaxKind::*, SyntaxNode, SyntaxToken, T, @@ -30,43 +29,6 @@ fn prev_tokens(token: SyntaxToken) -> impl Iterator { successors(token.prev_token(), |token| token.prev_token()) } -pub fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr { - extract_trivial_expression(&block) - .filter(|expr| !expr.syntax().text().contains_char('\n')) - .unwrap_or_else(|| block.into()) -} - -pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option { - let has_anything_else = |thing: &SyntaxNode| -> bool { - let mut non_trivial_children = - block.syntax().children_with_tokens().filter(|it| match it.kind() { - WHITESPACE | T!['{'] | T!['}'] => false, - _ => it.as_node() != Some(thing), - }); - non_trivial_children.next().is_some() - }; - - if let Some(expr) = block.expr() { - if has_anything_else(expr.syntax()) { - return None; - } - return Some(expr); - } - // Unwrap `{ continue; }` - let (stmt,) = block.statements().next_tuple()?; - if let ast::Stmt::ExprStmt(expr_stmt) = stmt { - if has_anything_else(expr_stmt.syntax()) { - return None; - } - let expr = expr_stmt.expr()?; - match expr.syntax().kind() { - CONTINUE_EXPR | BREAK_EXPR | RETURN_EXPR => return Some(expr), - _ => (), - } - } - None -} - pub fn compute_ws(left: SyntaxKind, right: SyntaxKind) -> &'static str { match left { T!['('] | T!['['] => return "", -- cgit v1.2.3