Skip to content

Commit

Permalink
Auto merge of #15426 - alibektas:deunwrap/convert_to_guarded_return, …
Browse files Browse the repository at this point in the history
…r=Veykril

minor : Deunwrap convert_to_guarded_return

Closes subtask 12 of #15398
  • Loading branch information
bors committed Aug 15, 2023
2 parents f73cd39 + ebf2705 commit 0b2a241
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions crates/ide-assists/src/handlers/convert_to_guarded_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<'
return None;
}

let bound_ident = pat.fields().next().unwrap();
let bound_ident = pat.fields().next()?;
if !ast::IdentPat::can_cast(bound_ident.syntax().kind()) {
return None;
}
Expand Down Expand Up @@ -108,6 +108,15 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<'

then_block.syntax().last_child_or_token().filter(|t| t.kind() == T!['}'])?;

let then_block_items = then_block.dedent(IndentLevel(1)).clone_for_update();

let end_of_then = then_block_items.syntax().last_child_or_token()?;
let end_of_then = if end_of_then.prev_sibling_or_token().map(|n| n.kind()) == Some(WHITESPACE) {
end_of_then.prev_sibling_or_token()?
} else {
end_of_then
};

let target = if_expr.syntax().text_range();
acc.add(
AssistId("convert_to_guarded_return", AssistKind::RefactorRewrite),
Expand Down Expand Up @@ -141,16 +150,6 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<'
}
};

let then_block_items = then_block.dedent(IndentLevel(1)).clone_for_update();

let end_of_then = then_block_items.syntax().last_child_or_token().unwrap();
let end_of_then =
if end_of_then.prev_sibling_or_token().map(|n| n.kind()) == Some(WHITESPACE) {
end_of_then.prev_sibling_or_token().unwrap()
} else {
end_of_then
};

let then_statements = replacement
.children_with_tokens()
.chain(
Expand Down

0 comments on commit 0b2a241

Please sign in to comment.