From 5e3f291195b580580be7ce5622f54ebca75fb9f0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 2 Sep 2019 21:23:19 +0300 Subject: fix hir for new block syntax --- crates/ra_assists/src/replace_if_let_with_match.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'crates/ra_assists/src/replace_if_let_with_match.rs') diff --git a/crates/ra_assists/src/replace_if_let_with_match.rs b/crates/ra_assists/src/replace_if_let_with_match.rs index c0bf6d235..401835c57 100644 --- a/crates/ra_assists/src/replace_if_let_with_match.rs +++ b/crates/ra_assists/src/replace_if_let_with_match.rs @@ -1,3 +1,4 @@ +use format_buf::format; use hir::db::HirDatabase; use ra_fmt::extract_trivial_expression; use ra_syntax::{ast, AstNode}; @@ -25,16 +26,21 @@ pub(crate) fn replace_if_let_with_match(mut ctx: AssistCtx) -> ctx.build() } -fn build_match_expr(expr: ast::Expr, pat1: ast::Pat, arm1: ast::Block, arm2: ast::Block) -> String { +fn build_match_expr( + expr: ast::Expr, + pat1: ast::Pat, + arm1: ast::BlockExpr, + arm2: ast::BlockExpr, +) -> String { let mut buf = String::new(); - buf.push_str(&format!("match {} {{\n", expr.syntax().text())); - buf.push_str(&format!(" {} => {}\n", pat1.syntax().text(), format_arm(&arm1))); - buf.push_str(&format!(" _ => {}\n", format_arm(&arm2))); + format!(buf, "match {} {{\n", expr.syntax().text()); + format!(buf, " {} => {}\n", pat1.syntax().text(), format_arm(&arm1)); + format!(buf, " _ => {}\n", format_arm(&arm2)); buf.push_str("}"); buf } -fn format_arm(block: &ast::Block) -> String { +fn format_arm(block: &ast::BlockExpr) -> String { match extract_trivial_expression(block) { None => block.syntax().text().to_string(), Some(e) => format!("{},", e.syntax().text()), -- cgit v1.2.3