mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 00:47:18 +00:00
Auto merge of #15426 - alibektas:deunwrap/convert_to_guarded_return, r=Veykril
minor : Deunwrap convert_to_guarded_return Closes subtask 12 of #15398
This commit is contained in:
commit
0b2a241b57
1 changed files with 10 additions and 11 deletions
|
@ -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;
|
||||
}
|
||||
|
@ -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),
|
||||
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue