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

Merged
merged 3 commits into from
Jul 6, 2025

Conversation

Zarathustra2
Copy link
Contributor

@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
@llogiq llogiq added this pull request to the merge queue Jul 6, 2025
@llogiq
Copy link
Contributor

llogiq commented Jul 6, 2025

Thank you! This is a good improvement.

Merged via the queue into rust-lang:master with commit cd679d6 Jul 6, 2025
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants