fix AST for if expressions

then is not always a block...
This commit is contained in:
Aleksey Kladov 2019-01-27 00:23:07 +03:00
parent 2d337c88b0
commit 619af1e22c
6 changed files with 112 additions and 5 deletions

View file

@ -11,7 +11,10 @@ pub fn replace_if_let_with_match(ctx: AssistCtx) -> Option<Assist> {
let pat = cond.pat()?;
let expr = cond.expr()?;
let then_block = if_expr.then_branch()?;
let else_block = if_expr.else_branch()?;
let else_block = match if_expr.else_branch()? {
ast::ElseBranchFlavor::Block(it) => it,
ast::ElseBranchFlavor::IfExpr(_) => return None,
};
ctx.build("replace with match", |edit| {
let match_expr = build_match_expr(expr, pat, then_block, else_block);