Merge pull request #20736 from A4-Tacks/fix-invert-if-let-chain

Fix applicable on if-let-chain for invert_if
This commit is contained in:
Shoyu Vanilla (Flint) 2025-09-26 05:36:52 +00:00 committed by GitHub
commit a96d92e9e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View file

@ -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(

View file

@ -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,