diff --git a/crates/ide-assists/src/handlers/invert_if.rs b/crates/ide-assists/src/handlers/invert_if.rs index d198870b02..7576d2fab9 100644 --- a/crates/ide-assists/src/handlers/invert_if.rs +++ b/crates/ide-assists/src/handlers/invert_if.rs @@ -124,6 +124,18 @@ mod tests { ) } + #[test] + fn invert_if_doesnt_apply_with_if_let_chain() { + check_assist_not_applicable( + invert_if, + "fn f() { i$0f x && let Some(_) = Some(1) { 1 } else { 0 } }", + ); + check_assist_not_applicable( + invert_if, + "fn f() { i$0f let Some(_) = Some(1) && x { 1 } else { 0 } }", + ); + } + #[test] fn invert_if_option_case() { check_assist( diff --git a/crates/ide-db/src/syntax_helpers/node_ext.rs b/crates/ide-db/src/syntax_helpers/node_ext.rs index cefd8fd496..e1d140730e 100644 --- a/crates/ide-db/src/syntax_helpers/node_ext.rs +++ b/crates/ide-db/src/syntax_helpers/node_ext.rs @@ -265,10 +265,7 @@ pub fn is_pattern_cond(expr: ast::Expr) -> bool { ast::Expr::BinExpr(expr) if expr.op_kind() == Some(ast::BinaryOp::LogicOp(ast::LogicOp::And)) => { - expr.lhs() - .map(is_pattern_cond) - .or_else(|| expr.rhs().map(is_pattern_cond)) - .unwrap_or(false) + expr.lhs().map_or(false, is_pattern_cond) || expr.rhs().map_or(false, is_pattern_cond) } ast::Expr::ParenExpr(expr) => expr.expr().is_some_and(is_pattern_cond), ast::Expr::LetExpr(_) => true,