Skip to content

Commit 0b2a241

Browse files
committed
Auto merge of rust-lang#15426 - alibektas:deunwrap/convert_to_guarded_return, r=Veykril
minor : Deunwrap convert_to_guarded_return Closes subtask 12 of rust-lang#15398
2 parents f73cd39 + ebf2705 commit 0b2a241

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

crates/ide-assists/src/handlers/convert_to_guarded_return.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<'
5858
return None;
5959
}
6060

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

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

111+
let then_block_items = then_block.dedent(IndentLevel(1)).clone_for_update();
112+
113+
let end_of_then = then_block_items.syntax().last_child_or_token()?;
114+
let end_of_then = if end_of_then.prev_sibling_or_token().map(|n| n.kind()) == Some(WHITESPACE) {
115+
end_of_then.prev_sibling_or_token()?
116+
} else {
117+
end_of_then
118+
};
119+
111120
let target = if_expr.syntax().text_range();
112121
acc.add(
113122
AssistId("convert_to_guarded_return", AssistKind::RefactorRewrite),
@@ -141,16 +150,6 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<'
141150
}
142151
};
143152

144-
let then_block_items = then_block.dedent(IndentLevel(1)).clone_for_update();
145-
146-
let end_of_then = then_block_items.syntax().last_child_or_token().unwrap();
147-
let end_of_then =
148-
if end_of_then.prev_sibling_or_token().map(|n| n.kind()) == Some(WHITESPACE) {
149-
end_of_then.prev_sibling_or_token().unwrap()
150-
} else {
151-
end_of_then
152-
};
153-
154153
let then_statements = replacement
155154
.children_with_tokens()
156155
.chain(

0 commit comments

Comments
 (0)