rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.62k stars 1.49k forks source link

Apply De Morgan's Law misses precedence of operations #17185

Closed l4l closed 5 days ago

l4l commented 2 weeks ago

Assist apply_demorgan for a && !(a && b) pointed at second operation produces a && !a || !b which is incorrect because the precedence of || is missed. Or more formally as a test:

#[test]
fn demorgan_keep_pars_for_op_precedence1() {
    check_assist(
        apply_demorgan,
        "fn f() { (a && !(b &&$0 c); }",
        "fn f() { (a && (!b || !c); }",
    );
}

Related #15239.


rust-analyzer version: rust-analyzer 1.76.0 (07dca48 2024-02-04)

rustc version: rustc 1.76.0 (07dca489a 2024-02-04)

editor or extension: helix

roife commented 2 weeks ago

@rustbot claim