Skip to content
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

Add suggestion for neg_multiply lint #8144

Merged
merged 4 commits into from
Dec 23, 2021
Merged

Conversation

Gh0stm4chine
Copy link
Contributor

@Gh0stm4chine Gh0stm4chine commented Dec 19, 2021

This fixes #8115 by adding a suggestion for [neg_multiply].

My first issue on Github, any feedback or input is welcome 😃

changelog: create a suggestion for neg_multiply

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @flip1995 (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 19, 2021
Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Gh0stm4chine and welcome to the project,
I've made some suggestions on how the code can be improved, the general direction was already good 👍.

One more thing related to the PR description: Clippy creates it's changelog based on the description. Could you include a text like this: changelog: create a suggestion for [`neg_multiply`] or something similar? Otherwise, everything looks good. Let me know if you have any more questions 🙃

clippy_lints/src/neg_multiply.rs Outdated Show resolved Hide resolved
tests/ui/neg_multiply.stderr Outdated Show resolved Hide resolved
tests/ui/neg_multiply.stderr Show resolved Hide resolved
clippy_lints/src/neg_multiply.rs Show resolved Hide resolved
cx,
NEG_MULTIPLY,
span,
"this `multiplication with -1` can be written more succinctly",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"this `multiplication with -1` can be written more succinctly",
"this multiplication with -1 can be written more succinctly",

It looks strange to me to put "multiplication with -1" in grave accents. Is there a reason for that? I would understand if it were * -1 or something similar that's actually code.
The old string (above) used grave accents only for the number -1 (which can be code):

-             span_lint(cx, NEG_MULTIPLY, span, "negation by multiplying with `-1`");

Maybe you meant to do that instead, if at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @r00ster91 ,
Yes you are right 👍 I will fix it.

@xFrednet
Copy link
Member

It looks good to me 👍. The pipeline failed as it was unable to apply one suggestion. This can happen when multiple suggestions overlap, but that shouldn't be the case here. I've restarted the pipeline to see if it works now.

Also thank you to @r00ster91 for the review comment 👍

@@ -1,3 +1,4 @@
// run-rustfix
#![warn(clippy::neg_multiply)]
#![allow(clippy::no_effect, clippy::unnecessary_operation)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#![allow(clippy::no_effect, clippy::unnecessary_operation)]
#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::precedence)]

The clippy::precedence lint triggers for the 0xcafe | 0xff00 * -1; expression. This causes the pipeline to fail. If you allow that lint and rerun the tests and update the output, everything should be fine 🙃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pipeline fails because it can't compile the fixed code. I tested it locally, it compiles fine 😕

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests can't be executed on Windows, if you use that it might explain this behavior. I'll check it out and try to find the problem 🙃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests fail due to the configuration of compiletest-rs. In the normal UI tests all lints inside the unused group are allowed, this is sadly not true for .fixed files. The problem can be solved by adding #![allow(unused)] to the file, as that will allow these lints and prevent the warnings that make the test fail.

(This is something I want to fix at some point, but for now, this is the best and easiest solution. Sorry that you ran into this 😅)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests can't be executed on Windows, if you use that it might explain this behavior. I'll check it out and try to find the problem 🙃

Yes, I am on Windows, but actually running the test locally was failing too. I thought the problem was about compiling the .fixed file.

The tests fail due to the configuration of compiletest-rs. In the normal UI tests all lints inside the unused group are allowed, this is sadly not true for .fixed files. The problem can be solved by adding #![allow(unused)] to the file, as that will allow these lints and prevent the warnings that make the test fail.

I was not sure if the #![allow(unused)] should be added in the .fixed only even though it's a generated file ?
I added it in test file for now.

Copy link
Member

@xFrednet xFrednet Dec 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am on Windows, but actually running the test locally was failing too. I thought the problem was about compiling the .fixed file.

Alright, your assumption was correct, it was with the compilation of the .fixed files.

I was not sure if the #![allow(unused)] should be added in the .fixed only even though it's a generated file?
I added it in test file for now.

You did it correctly, that's what I meant 👍

@xFrednet
Copy link
Member

Looks good to me, thank you for the quick changes 🙃

@bors r+

@bors
Copy link
Contributor

bors commented Dec 23, 2021

📌 Commit 13cc452 has been approved by xFrednet

@bors
Copy link
Contributor

bors commented Dec 23, 2021

⌛ Testing commit 13cc452 with merge 9ae4043...

@bors
Copy link
Contributor

bors commented Dec 23, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: xFrednet
Pushing 9ae4043 to master...

@bors bors merged commit 9ae4043 into rust-lang:master Dec 23, 2021
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.

neg_multiply should show a suggestion
6 participants