minor : Deunwrap convert_to_guarded_return
This commit is contained in:
parent
b64e5b3919
commit
ebf27058cd
@ -58,7 +58,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<'
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let bound_ident = pat.fields().next().unwrap();
|
let bound_ident = pat.fields().next()?;
|
||||||
if !ast::IdentPat::can_cast(bound_ident.syntax().kind()) {
|
if !ast::IdentPat::can_cast(bound_ident.syntax().kind()) {
|
||||||
return None;
|
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!['}'])?;
|
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();
|
let target = if_expr.syntax().text_range();
|
||||||
acc.add(
|
acc.add(
|
||||||
AssistId("convert_to_guarded_return", AssistKind::RefactorRewrite),
|
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
|
let then_statements = replacement
|
||||||
.children_with_tokens()
|
.children_with_tokens()
|
||||||
.chain(
|
.chain(
|
||||||
|
Loading…
Reference in New Issue
Block a user