Skip to content

Commit b92ed11

Browse files
committed
fix: Fix apply_demorgan assist hanging for certain binary expressions
1 parent bd91327 commit b92ed11

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

crates/ide_assists/src/handlers/apply_demorgan.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext) -> Option<(
4242

4343
// Walk up the tree while we have the same binary operator
4444
while let Some(parent_expr) = expr.syntax().parent().and_then(ast::BinExpr::cast) {
45-
if let Some(parent_op) = expr.op_kind() {
46-
if parent_op == op {
47-
expr = parent_expr
45+
match expr.op_kind() {
46+
Some(parent_op) if parent_op == op => {
47+
expr = parent_expr;
4848
}
49+
_ => break,
4950
}
5051
}
5152

@@ -220,4 +221,14 @@ fn f() { !(S <= S || S < S) }
220221
cov_mark::check!(demorgan_double_parens);
221222
check_assist(apply_demorgan, "fn f() { (x ||$0 x) }", "fn f() { !(!x && !x) }")
222223
}
224+
225+
// https://github.com/rust-analyzer/rust-analyzer/issues/10963
226+
#[test]
227+
fn demorgan_doesnt_hang() {
228+
check_assist(
229+
apply_demorgan,
230+
"fn f() { 1 || 3 &&$0 4 || 5 }",
231+
"fn f() { !(!1 || !3 || !4) || 5 }",
232+
)
233+
}
223234
}

0 commit comments

Comments
 (0)