Skip to content

Commit 45201ff

Browse files
committed
Fix demorgan applicable on pattern conditional
Example --- ```rust fn f() { if let 1 = 1 &&$0 true { } } ``` **Before this PR** ```rust fn f() { if !(!let 1 = 1 || false) { } } ``` **After this PR** Assist not applicable
1 parent adbff8b commit 45201ff

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::VecDeque;
33
use ide_db::{
44
assists::GroupLabel,
55
famous_defs::FamousDefs,
6-
syntax_helpers::node_ext::{for_each_tail_expr, walk_expr},
6+
syntax_helpers::node_ext::{for_each_tail_expr, is_pattern_cond, walk_expr},
77
};
88
use syntax::{
99
NodeOrToken, SyntaxKind, T,
@@ -69,6 +69,10 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
6969
}
7070
}
7171

72+
if is_pattern_cond(bin_expr.clone().into()) {
73+
return None;
74+
}
75+
7276
let op = bin_expr.op_kind()?;
7377
let (inv_token, prec) = match op {
7478
ast::BinaryOp::LogicOp(ast::LogicOp::And) => (SyntaxKind::PIPE2, ExprPrecedence::LOr),
@@ -375,6 +379,16 @@ fn f() { !(S <= S || S < S) }
375379
)
376380
}
377381

382+
#[test]
383+
fn demorgan_doesnt_handles_pattern() {
384+
check_assist_not_applicable(
385+
apply_demorgan,
386+
r#"
387+
fn f() { if let 1 = 1 &&$0 true { } }
388+
"#,
389+
);
390+
}
391+
378392
#[test]
379393
fn demorgan_on_not() {
380394
check_assist(

0 commit comments

Comments
 (0)