mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-27 18:26:19 +00:00
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:
commit
a96d92e9e9
2 changed files with 13 additions and 4 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue