From bf26e13cd252a6337aa290adf842bf72e2523c4d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 10 May 2021 15:25:56 +0300 Subject: simplify --- .../src/handlers/replace_let_with_if_let.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'crates/ide_assists/src/handlers') 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) -> "Replace with if-let", target, |edit| { - let with_placeholder: ast::Pat = match happy_variant { - None => make::wildcard_pat().into(), - Some(var_name) => make::tuple_struct_pat( - make::ext::ident_path(var_name), - once(make::wildcard_pat().into()), - ) - .into(), + let pat = match happy_variant { + None => original_pat, + Some(var_name) => { + make::tuple_struct_pat(make::ext::ident_path(var_name), once(original_pat)) + .into() + } }; + let block = - make::block_expr(None, None).indent(IndentLevel::from_node(let_stmt.syntax())); - let if_ = make::expr_if(make::condition(init, Some(with_placeholder)), block, None); + make::ext::empty_block_expr().indent(IndentLevel::from_node(let_stmt.syntax())); + let if_ = make::expr_if(make::condition(init, Some(pat)), block, None); let stmt = make::expr_stmt(if_); - let placeholder = stmt.syntax().descendants().find_map(ast::WildcardPat::cast).unwrap(); - let stmt = stmt.replace_descendant(placeholder.into(), original_pat); - edit.replace_ast(ast::Stmt::from(let_stmt), ast::Stmt::from(stmt)); }, ) -- cgit v1.2.3