Skip to content

Commit a96d92e

Browse files
authored
Merge pull request #20736 from A4-Tacks/fix-invert-if-let-chain
Fix applicable on if-let-chain for invert_if
2 parents 750d566 + 39ef6c2 commit a96d92e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ mod tests {
124124
)
125125
}
126126

127+
#[test]
128+
fn invert_if_doesnt_apply_with_if_let_chain() {
129+
check_assist_not_applicable(
130+
invert_if,
131+
"fn f() { i$0f x && let Some(_) = Some(1) { 1 } else { 0 } }",
132+
);
133+
check_assist_not_applicable(
134+
invert_if,
135+
"fn f() { i$0f let Some(_) = Some(1) && x { 1 } else { 0 } }",
136+
);
137+
}
138+
127139
#[test]
128140
fn invert_if_option_case() {
129141
check_assist(

crates/ide-db/src/syntax_helpers/node_ext.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,7 @@ pub fn is_pattern_cond(expr: ast::Expr) -> bool {
265265
ast::Expr::BinExpr(expr)
266266
if expr.op_kind() == Some(ast::BinaryOp::LogicOp(ast::LogicOp::And)) =>
267267
{
268-
expr.lhs()
269-
.map(is_pattern_cond)
270-
.or_else(|| expr.rhs().map(is_pattern_cond))
271-
.unwrap_or(false)
268+
expr.lhs().map_or(false, is_pattern_cond) || expr.rhs().map_or(false, is_pattern_cond)
272269
}
273270
ast::Expr::ParenExpr(expr) => expr.expr().is_some_and(is_pattern_cond),
274271
ast::Expr::LetExpr(_) => true,

0 commit comments

Comments
 (0)