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

New lint: detect if expressions with simple boolean assignments to the same target #10432

Merged
merged 1 commit into from Apr 23, 2023

Conversation

samueltardieu
Copy link
Contributor

@samueltardieu samueltardieu commented Mar 1, 2023

Closes #10430

changelog: [needless_bool_assign] new lint to detect simple boolean assignment to the same target in if branches

@rustbot
Copy link
Collaborator

rustbot commented Mar 1, 2023

r? @Manishearth

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 1, 2023
@matthiaskrgr
Copy link
Member

matthiaskrgr commented Mar 1, 2023

If we have comments inside the if expr that explain what is happening, will clippy remove these? This might be annoying :/

    if needless_bool_condition() {
    // the crazy brown fox
        a.field = true;
    } else {
    // jumps over the lazy cow
        a.field = true;
    }

@Manishearth
Copy link
Member

Yeah I'm concerned about sticking this within an existing lint, and worried about impact.

@samueltardieu
Copy link
Contributor Author

I agree with both remarks. I'll make this into a new lint and check for comments. I'll put it in draft status in the meantime.

@samueltardieu samueltardieu marked this pull request as draft March 1, 2023 22:55
@samueltardieu samueltardieu force-pushed the issue-10430 branch 2 times, most recently from cf45b1b to e99e89f Compare March 2, 2023 12:15
@samueltardieu samueltardieu changed the title Detect if expressions with simple boolean assignments to the same target New lint: detect if expressions with simple boolean assignments to the same target Mar 2, 2023
@samueltardieu samueltardieu marked this pull request as ready for review March 2, 2023 12:19
@samueltardieu
Copy link
Contributor Author

@Manishearth I made it into a new lint.

@matthiaskrgr The lint does not trigger when there are comments in the if expression being linted.

Note that expanded code is excluded already.

@Manishearth
Copy link
Member

cc @rust-lang/clippy Do we think this lint is going to be too noisy? Should we nursery it first or something?

@samueltardieu
Copy link
Contributor Author

I don't expect this lint to trigger much except on beginner programmers' code (as does needless_bool) but I might be wrong.

@xFrednet
Copy link
Member

xFrednet commented Mar 4, 2023

cc @rust-lang/clippy Do we think this lint is going to be too noisy? Should we nursery it first or something?

If we want to have a trial period, I'd first put this into pedantic. Though I'd guess that it won't be noisy if it really just checks for assignments and nothing else. Having it warn-by-default will probably be fine. Maybe let's see what lintcheck or another tool with more crates says?

@samueltardieu
Copy link
Contributor Author

Maybe let's see what lintcheck or another tool with more crates says?

lintcheck does not trigger this lint. Running it with --filter needless_bool_assign yields:

clippy 0.1.69

### Reports



### Stats:

| lint                                               | count |
| -------------------------------------------------- | ----- |


### ICEs:

@samueltardieu
Copy link
Contributor Author

Checked with the 500 most recently downloaded crates of crates.io: this lint was not triggered (the complete 470klines report is available at https://rfc1149.net/tmp/top500_logs.txt.gz).

@samueltardieu
Copy link
Contributor Author

@Manishearth Is there anything more you'd like me to do on this one?

@Manishearth
Copy link
Member

I don't think we have consensus as a team on whether we should release this lint enabled by default.

(Also I'm a bit busy and will be slow to review)

@samueltardieu
Copy link
Contributor Author

samueltardieu commented Apr 23, 2023

This has been lingering for more than one month now. What is the next step?

(I'll rebase it in the meantime)

@Manishearth
Copy link
Member

@bors r+

given lintcheck results I guess it's fine

@bors
Copy link
Collaborator

bors commented Apr 23, 2023

📌 Commit 69da902 has been approved by Manishearth

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Apr 23, 2023

⌛ Testing commit 69da902 with merge 7a870ae...

@bors
Copy link
Collaborator

bors commented Apr 23, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Manishearth
Pushing 7a870ae to master...

@bors bors merged commit 7a870ae into rust-lang:master Apr 23, 2023
8 checks passed
@samueltardieu samueltardieu deleted the issue-10430 branch November 29, 2023 22:41
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.

if else statement that sets booleans
6 participants