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

Fix false positive unconditional_recursion #12062

Conversation

GuillaumeGomez
Copy link
Member

Fixes #12052.

Only checking if both variables are local was not enough, we also need to confirm they have the same type as Self.

changelog: Fix false positive for unconditional_recursion lint

@rustbot
Copy link
Collaborator

rustbot commented Dec 30, 2023

r? @xFrednet

(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 Dec 30, 2023
@Jarcho
Copy link
Contributor

Jarcho commented Dec 30, 2023

Is there any reason for expression type constraints? The only thing that matters for recursion checking are the types of the lhs and rhs of the operator.

@GuillaumeGomez
Copy link
Member Author

Unless I missed something, we don't know which method is called just from here. It is much simpler to instead check the types of lhs and rhs and compare it with self.

@Jarcho
Copy link
Contributor

Jarcho commented Dec 30, 2023

Sorry, I worded that badly. I meant the constraint that the lhs and rhs are both locals.

@y21
Copy link
Member

y21 commented Dec 30, 2023

Maybe this should should also check that there aren't any other explicit returns in the function body, since that can act as the recursion base case?
E.g. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7abd6a54f7908a965cdd496144343a6d is fine, but we still emit a warning for that with this fix, right?

@GuillaumeGomez GuillaumeGomez force-pushed the fix-false-positive-unconditional_recursion branch from 9626c5e to f3be069 Compare December 30, 2023 18:48
@GuillaumeGomez
Copy link
Member Author

Sorry, I worded that badly. I meant the constraint that the lhs and rhs are both locals.

You're right, it doesn't make much sense. I'll remove this check.

@y21: That's a good point. I changed how I check it to ensure that there is no other return statements. If you have other test cases, please share them. :)

@bors
Copy link
Collaborator

bors commented Dec 31, 2023

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

@GuillaumeGomez GuillaumeGomez force-pushed the fix-false-positive-unconditional_recursion branch from f3be069 to 1212a7d Compare December 31, 2023 10:18
@GuillaumeGomez GuillaumeGomez force-pushed the fix-false-positive-unconditional_recursion branch from 1212a7d to 7107aa2 Compare December 31, 2023 10:20
@GuillaumeGomez
Copy link
Member Author

Fixed merge conflict.

@xFrednet
Copy link
Member

xFrednet commented Jan 3, 2024

LGTM, thank you for the update :D

@bors r+

@bors
Copy link
Collaborator

bors commented Jan 3, 2024

📌 Commit 7107aa2 has been approved by xFrednet

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jan 3, 2024

⌛ Testing commit 7107aa2 with merge 0153ca9...

@bors
Copy link
Collaborator

bors commented Jan 3, 2024

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

@bors bors merged commit 0153ca9 into rust-lang:master Jan 3, 2024
5 checks passed
@GuillaumeGomez GuillaumeGomez deleted the fix-false-positive-unconditional_recursion branch January 3, 2024 11:38
@faern
Copy link
Contributor

faern commented Jan 10, 2024

How often are Clippy releases cut for nightly? I have a project where I use nightly rustc/clippy for various reasons, and I get this false positive even for clippy 0.1.77 (190f4c9 2024-01-09)

@GuillaumeGomez
Copy link
Member Author

I think it has been released so if you have a case, please open a new issue with a minimal code to reproduce it and tag me on it so I can fix it.

@faern
Copy link
Contributor

faern commented Jan 10, 2024

Sure! Done: #12118. Thank you for your work on this!

@flip1995
Copy link
Member

This is not synced yet. It will be synced tomorrow, so it will be in the nightly version of Friday 2024-01-12

@faern
Copy link
Contributor

faern commented Jan 10, 2024

So how does one figure out what version of the code one's clippy is running? Since I was running nightly and the date printed by cargo clippy --version was about a week after when the fix was merged? Since it's nightly I assumed it was the main branch at that date? Is there a good way way in general for a user to figure out?

@flip1995
Copy link
Member

flip1995 commented Jan 10, 2024

You can't. Syncs are every other week on Thursday. This is documented in our book. So you have to know the Clippy sync process and how Rust releases work.

We can't really give better version info, as the Clippy that is shipped with rustup is built in the Rust repo. And as far as that Clippy version is concerned, it is the one from that nightly. However, that version lacks behind by up to 2 weeks (by design).

If there is an important fix, that blocks our users, we're open to requests to do an out-of-cylce sync, so that it gets into nightly earlier. But as the Clippy update is planned for tomorrow, I too lazy to do an additional sync today 😅

@faern
Copy link
Contributor

faern commented Jan 10, 2024

Thank you for the explanation! That makes sense and I understand doing it differently is hard/has other drawbacks! Optimally cargo clippy --version would print the date of when the source code was branched/synced from this repo, not when it was compiled.

@GuillaumeGomez
Copy link
Member Author

That's worth opening an issue to update --version or provide additional information.

@flip1995
Copy link
Member

FWIW, this is the command I'm using to find out the Clippy commit of the last sync in the Rust repo:

git log --oneline -- src/tools/clippy/ | grep -o "Merge commit '[a-f0-9]*' into .*" | head -1 | sed -e "s/Merge commit '\([a-f0-9]*\)' into .*/\1/g"

However, this depends on the exact commit message. If someone would change that during sync, this would no longer work. So using that to get more version information for --version is really flaky.

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.

unconditional_recursion false positive in PartialEq field comparison
8 participants