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

Uplift clippy::double_neg lint as double_negations #126604

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

Conversation

kadiwa4
Copy link
Contributor

@kadiwa4 kadiwa4 commented Jun 17, 2024

Warns about cases like this:

fn main() {
    let x = 1;
    let _b = --x; //~ WARN use of a double negation
}

The intent is to keep people from thinking that --x is a prefix decrement operator. ++x, x++ and x-- are invalid expressions and already have a helpful diagnostic.

I didn't add a machine-applicable suggestion to the lint because it's not entirely clear what the programmer was trying to achieve with the --x operation. The code that triggers the lint should always be reviewed manually.

Closes #82987

@rustbot
Copy link
Collaborator

rustbot commented Jun 17, 2024

r? @nnethercote

rustbot has assigned @nnethercote.
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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 17, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jun 17, 2024

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rust-log-analyzer

This comment has been minimized.

@kadiwa4 kadiwa4 force-pushed the uplift_double_negation branch from af85271 to a745a8d Compare June 17, 2024 18:22
@kadiwa4
Copy link
Contributor Author

kadiwa4 commented Jun 18, 2024

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 18, 2024
@compiler-errors compiler-errors added T-lang Relevant to the language team, which will review and decide on the PR/issue. I-lang-nominated Nominated for discussion during a lang team meeting. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 18, 2024
@nnethercote
Copy link
Contributor

This needs T-lang approval. The appropriate labels have been applied to summon them.

@bors
Copy link
Contributor

bors commented Jun 30, 2024

☔ The latest upstream changes (presumably #127174) made this pull request unmergeable. Please resolve the merge conflicts.

@kadiwa4 kadiwa4 force-pushed the uplift_double_negation branch from a745a8d to 8f3387c Compare September 1, 2024 17:25
@kadiwa4 kadiwa4 changed the title Uplift clippy::double_neg lint as double_negation Uplift clippy::double_neg lint as double_negations Sep 1, 2024
@rust-log-analyzer

This comment has been minimized.

@kadiwa4 kadiwa4 force-pushed the uplift_double_negation branch from 8f3387c to 9862f05 Compare September 1, 2024 18:01
@kadiwa4
Copy link
Contributor Author

kadiwa4 commented Sep 1, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 1, 2024
@nnethercote
Copy link
Contributor

Still waiting on T-lang, AFAICT.

@kadiwa4
Copy link
Contributor Author

kadiwa4 commented Sep 30, 2024

@rustbot label: -S-waiting-on-review +S-waiting-on-team

@rustbot rustbot added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 30, 2024
@bors
Copy link
Contributor

bors commented Oct 29, 2024

☔ The latest upstream changes (presumably #128985) made this pull request unmergeable. Please resolve the merge conflicts.

@kadiwa4 kadiwa4 force-pushed the uplift_double_negation branch from 9862f05 to beb1dd2 Compare October 29, 2024 19:54
@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Jan 12, 2025
@joshtriplett joshtriplett added the I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination label Jan 12, 2025
@kadiwa4 kadiwa4 force-pushed the uplift_double_negation branch from 5b59711 to d3cbf72 Compare January 12, 2025 13:43
@traviscross
Copy link
Contributor

traviscross commented Jan 12, 2025

I looked around on GitHub for anyone using this. The main use case I found is that people who have implemented Neg for a type then tend to write a test or fuzzing code that looks like this:

fn test_neg_is_own_inverse() {
    let x = MyType::new(42);
    assert_eq!(x, --x);
}

It's probably fine to use parentheses there.

@rfcbot reviewed

@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

I see no harm in writing -(-x) -- I would definitely prefer that.

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Jan 13, 2025
@rfcbot
Copy link

rfcbot commented Jan 13, 2025

🔔 This is now entering its final comment period, as per the review above. 🔔

@scottmcm
Copy link
Member

Makes sense to me! It's not something that people would normally write, so worth linting since x = --y won't trip unused.

(I guess they could use it as a really obscure way to debug_assert!(y != MIN), but how about no.)

@rfcbot reviewed

while let Some(LintDeclSearchResult { content, .. }) = iter.find(|result| result.token == TokenKind::Ident) {
while let Some(LintDeclSearchResult { content, .. }) = iter.find(|result| result.token_kind == TokenKind::Ident) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes were necessary to get the clippy dev tool to compile

Comment on lines -16 to +17
#![allow(clippy::manual_find_map)]
#![allow(clippy::manual_filter_map)]
#![allow(unpredictable_function_pointer_comparisons)]
#![allow(clippy::manual_find_map)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is supposed to be auto-generated (it has a comment at the top saying so), but most people seem to edit it manually. I used the generator though, that's why so many lines are changed in this file.

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jan 23, 2025
@rfcbot
Copy link

rfcbot commented Jan 23, 2025

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@bors
Copy link
Contributor

bors commented Jan 26, 2025

☔ The latest upstream changes (presumably #136070) made this pull request unmergeable. Please resolve the merge conflicts.

@kadiwa4 kadiwa4 force-pushed the uplift_double_negation branch from d3cbf72 to c1dcbeb Compare January 26, 2025 11:18
@kadiwa4
Copy link
Contributor Author

kadiwa4 commented Jan 26, 2025

@rustbot label: -S-waiting-on-team +S-waiting-on-review -I-lang-nominated

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). I-lang-nominated Nominated for discussion during a lang team meeting. labels Jan 26, 2025
@nnethercote
Copy link
Contributor

Updated code looks fine to me. I think/hope this has gone through all the appropriate hoops and is ready to be merged.

@bors r+

@bors
Copy link
Contributor

bors commented Jan 26, 2025

📌 Commit c1dcbeb has been approved by nnethercote

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uplift clippy::double_neg into rustc