fix: Fix apply_demorgan assist hanging for certain binary expressions

This commit is contained in:
Lukas Wirth 2022-01-05 22:30:19 +01:00
parent bd91327079
commit b92ed115c1

View file

@ -42,10 +42,11 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext) -> Option<(
// Walk up the tree while we have the same binary operator
while let Some(parent_expr) = expr.syntax().parent().and_then(ast::BinExpr::cast) {
if let Some(parent_op) = expr.op_kind() {
if parent_op == op {
expr = parent_expr
match expr.op_kind() {
Some(parent_op) if parent_op == op => {
expr = parent_expr;
}
_ => break,
}
}
@ -220,4 +221,14 @@ fn f() { !(S <= S || S < S) }
cov_mark::check!(demorgan_double_parens);
check_assist(apply_demorgan, "fn f() { (x ||$0 x) }", "fn f() { !(!x && !x) }")
}
// https://github.com/rust-analyzer/rust-analyzer/issues/10963
#[test]
fn demorgan_doesnt_hang() {
check_assist(
apply_demorgan,
"fn f() { 1 || 3 &&$0 4 || 5 }",
"fn f() { !(!1 || !3 || !4) || 5 }",
)
}
}