Skip to content

"Apply De Morgan's Law" on _ = !a && (b); generates invalid code #15240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DropDemBits opened this issue Jul 9, 2023 · 2 comments
Closed

"Apply De Morgan's Law" on _ = !a && (b); generates invalid code #15240

DropDemBits opened this issue Jul 9, 2023 · 2 comments
Assignees
Labels
A-assists C-bug Category: bug

Comments

@DropDemBits
Copy link
Contributor

DropDemBits commented Jul 9, 2023

Applying the assist as follows:

fn main() {
    _ = !a &&$0 (b);
}

Generates the following code:

fn main() {
    !(!_ || a || !(b));
}

A similar issue occurs when you start with _ = !a ||$0 (b); instead.


rust-analyzer version: rust-analyzer version: 0.3.1575-standalone (ff485b6 2023-07-02)

rustc version: rustc 1.70.0 (90c541806 2023-05-31)

relevant settings: Not Applicable

@DropDemBits DropDemBits added the C-bug Category: bug label Jul 9, 2023
@alibektas
Copy link
Member

@rustbot claim

bors added a commit that referenced this issue Aug 15, 2023
internal : rewrite DeMorgan assist

fixes #15239 , #15240 . This PR is a rewrite of the DeMorgan assist that essentially rids of all the string manipulation and modifies syntax trees to apply demorgan on a binary expr. The main reason for the rewrite is that I wanted to use `Expr::needs_parens_in` method to see if the expr on which the assist is applied would still need the parens it had once the parent expression's operator had equal precedence with that of the expression. I used `.clone_(subtree|for_update)` left and right and probably more than I should have, so I would also be happy to hear how I could have prevented redundant cloning.
@alibektas
Copy link
Member

#15410 should have closed this one too. Can you mark this as resolved @Veykril ?

@Veykril Veykril closed this as completed Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants