diff options
author | Aleksey Kladov <[email protected]> | 2021-05-10 13:25:56 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-05-10 13:25:56 +0100 |
commit | bf26e13cd252a6337aa290adf842bf72e2523c4d (patch) | |
tree | 9970300ac753fa7856defc709a73fc886d55880c /crates/ide_assists | |
parent | fd109fb587904cfecc1149e068814bfd38feb83c (diff) |
simplify
Diffstat (limited to 'crates/ide_assists')
-rw-r--r-- | crates/ide_assists/src/handlers/replace_let_with_if_let.rs | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/crates/ide_assists/src/handlers/replace_let_with_if_let.rs b/crates/ide_assists/src/handlers/replace_let_with_if_let.rs index f811234c0..1ad0fa816 100644 --- a/crates/ide_assists/src/handlers/replace_let_with_if_let.rs +++ b/crates/ide_assists/src/handlers/replace_let_with_if_let.rs | |||
@@ -50,22 +50,19 @@ pub(crate) fn replace_let_with_if_let(acc: &mut Assists, ctx: &AssistContext) -> | |||
50 | "Replace with if-let", | 50 | "Replace with if-let", |
51 | target, | 51 | target, |
52 | |edit| { | 52 | |edit| { |
53 | let with_placeholder: ast::Pat = match happy_variant { | 53 | let pat = match happy_variant { |
54 | None => make::wildcard_pat().into(), | 54 | None => original_pat, |
55 | Some(var_name) => make::tuple_struct_pat( | 55 | Some(var_name) => { |
56 | make::ext::ident_path(var_name), | 56 | make::tuple_struct_pat(make::ext::ident_path(var_name), once(original_pat)) |
57 | once(make::wildcard_pat().into()), | 57 | .into() |
58 | ) | 58 | } |
59 | .into(), | ||
60 | }; | 59 | }; |
60 | |||
61 | let block = | 61 | let block = |
62 | make::block_expr(None, None).indent(IndentLevel::from_node(let_stmt.syntax())); | 62 | make::ext::empty_block_expr().indent(IndentLevel::from_node(let_stmt.syntax())); |
63 | let if_ = make::expr_if(make::condition(init, Some(with_placeholder)), block, None); | 63 | let if_ = make::expr_if(make::condition(init, Some(pat)), block, None); |
64 | let stmt = make::expr_stmt(if_); | 64 | let stmt = make::expr_stmt(if_); |
65 | 65 | ||
66 | let placeholder = stmt.syntax().descendants().find_map(ast::WildcardPat::cast).unwrap(); | ||
67 | let stmt = stmt.replace_descendant(placeholder.into(), original_pat); | ||
68 | |||
69 | edit.replace_ast(ast::Stmt::from(let_stmt), ast::Stmt::from(stmt)); | 66 | edit.replace_ast(ast::Stmt::from(let_stmt), ast::Stmt::from(stmt)); |
70 | }, | 67 | }, |
71 | ) | 68 | ) |