// ```
pub(crate) fn replace_let_with_if_let(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let let_kw = ctx.find_token_syntax_at_offset(T![let])?;
- let let_stmt = let_kw.ancestors().find_map(ast::LetStmt::cast)?;
+ let let_stmt = let_kw.parent().and_then(ast::LetStmt::cast)?;
let init = let_stmt.initializer()?;
let original_pat = let_stmt.pat()?;
let block =
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 if_ = make::expr_if(make::expr_let(pat, init).into(), block, None);
let stmt = make::expr_stmt(if_);
edit.replace_ast(ast::Stmt::from(let_stmt), ast::Stmt::from(stmt));