Skip to content

Commit 5a1b45d

Browse files
pocket7878Veykril
andcommitted
feature: Simplfy branch check logics
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
1 parent a5d2463 commit 5a1b45d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ pub(crate) fn convert_two_arm_bool_match_to_matches_macro(
2626
) -> Option<()> {
2727
let match_expr = ctx.find_node_at_offset::<ast::MatchExpr>()?;
2828
let match_arm_list = match_expr.match_arm_list()?;
29-
if match_arm_list.arms().count() != 2 {
29+
let mut arms = match_arm_list.arms();
30+
let first_arm = arms.next()?;
31+
let second_arm = arms.next()?;
32+
if arms.next().is_some() {
3033
cov_mark::hit!(non_two_arm_match);
3134
return None;
3235
}
33-
34-
let first_arm = match_arm_list.arms().next()?;
3536
let first_arm_expr = first_arm.expr();
3637

37-
let invert_matches;
38-
if is_bool_literal_expr(&first_arm_expr, true) {
39-
invert_matches = false;
38+
let invert_matches = if is_bool_literal_expr(&first_arm_expr, true) {
39+
false
4040
} else if is_bool_literal_expr(&first_arm_expr, false) {
41-
invert_matches = true;
41+
true
4242
} else {
4343
cov_mark::hit!(non_bool_literal_match);
4444
return None;
45-
}
45+
};
4646

4747
let target_range = ctx.sema.original_range(match_expr.syntax()).range;
4848
let expr = match_expr.expr()?;

0 commit comments

Comments
 (0)