diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-19 12:15:55 +0100 |
---|---|---|
committer | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-19 12:15:55 +0100 |
commit | f209843e31af7f0e0212aa28ffec2efad2a70c6f (patch) | |
tree | 548227da78a3bea644f57714d075410c0bdf7469 /crates/ra_assists/src/replace_if_let_with_match.rs | |
parent | 58d4983ba5745975446d60f2886d96f8d2adf0f2 (diff) | |
parent | d4a66166c002f0a49e41d856a49cb5685ac93202 (diff) |
Merge #1545
1545: migrate ra_syntax to the new rowan API r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/replace_if_let_with_match.rs')
-rw-r--r-- | crates/ra_assists/src/replace_if_let_with_match.rs | 13 |
1 files changed, 4 insertions, 9 deletions
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 c2c7cf70b..5de6aa266 100644 --- a/crates/ra_assists/src/replace_if_let_with_match.rs +++ b/crates/ra_assists/src/replace_if_let_with_match.rs | |||
@@ -5,7 +5,7 @@ use ra_syntax::{ast, AstNode}; | |||
5 | use crate::{Assist, AssistCtx, AssistId}; | 5 | use crate::{Assist, AssistCtx, AssistId}; |
6 | 6 | ||
7 | pub(crate) fn replace_if_let_with_match(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 7 | pub(crate) fn replace_if_let_with_match(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
8 | let if_expr: &ast::IfExpr = ctx.node_at_offset()?; | 8 | let if_expr: ast::IfExpr = ctx.node_at_offset()?; |
9 | let cond = if_expr.condition()?; | 9 | let cond = if_expr.condition()?; |
10 | let pat = cond.pat()?; | 10 | let pat = cond.pat()?; |
11 | let expr = cond.expr()?; | 11 | let expr = cond.expr()?; |
@@ -25,16 +25,11 @@ pub(crate) fn replace_if_let_with_match(mut ctx: AssistCtx<impl HirDatabase>) -> | |||
25 | ctx.build() | 25 | ctx.build() |
26 | } | 26 | } |
27 | 27 | ||
28 | fn build_match_expr( | 28 | fn build_match_expr(expr: ast::Expr, pat1: ast::Pat, arm1: ast::Block, arm2: ast::Block) -> String { |
29 | expr: &ast::Expr, | ||
30 | pat1: &ast::Pat, | ||
31 | arm1: &ast::Block, | ||
32 | arm2: &ast::Block, | ||
33 | ) -> String { | ||
34 | let mut buf = String::new(); | 29 | let mut buf = String::new(); |
35 | buf.push_str(&format!("match {} {{\n", expr.syntax().text())); | 30 | buf.push_str(&format!("match {} {{\n", expr.syntax().text())); |
36 | buf.push_str(&format!(" {} => {}\n", pat1.syntax().text(), format_arm(arm1))); | 31 | buf.push_str(&format!(" {} => {}\n", pat1.syntax().text(), format_arm(&arm1))); |
37 | buf.push_str(&format!(" _ => {}\n", format_arm(arm2))); | 32 | buf.push_str(&format!(" _ => {}\n", format_arm(&arm2))); |
38 | buf.push_str("}"); | 33 | buf.push_str("}"); |
39 | buf | 34 | buf |
40 | } | 35 | } |