Skip to content

FIX: NegMultiply should preserve parenthesis when method is called #15179

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Zarathustra2
Copy link

@Zarathustra2 Zarathustra2 commented Jun 30, 2025

Hi,

I noticed that the lint neg_multiply generates bad code when we call a method on the expression.
Consider ((a.delta - 0.5).abs() * -1.0).total_cmp(&1.0). Currently this would be changed by clippy to -(a.delta - 0.5).abs() .total_cmp(&1.0) - which does not compile because we are trying to negate an ordering enum - but what we really want is (-(a.delta - 0.5).abs()).total_cmp(&1.0).

This PR fixes this.

changelog: [neg_multiply] does not remove parenthesis anymore if a method is being called on the affected expression

NOTE: This is the first time I am contributing to clippy or the rust repo in general. So I am not sure whether my approach to fixing this issue is goo, if there are better solutions or if I missed something.

Thanks & hope you have a good day,
Dario

changelog: [`neg_multiply`] does not remove parenthesis anymore if a method
is being called on the affected expression
@rustbot
Copy link
Collaborator

rustbot commented Jun 30, 2025

r? @llogiq

rustbot has assigned @llogiq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants