-
Notifications
You must be signed in to change notification settings - Fork 1.6k
branches_sharing_code reporting a false positive #7452
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
Comments
Suggesting label change to |
@rustbot label +I-suggestion-causes-error -I-false-positive |
This kind of fits both labels, I'm going over a possible solution in my head and might claim this issue :) |
…p, r=camsteffen FP fix and documentation for `branches_sharing_code` lint Closes #7369 Related #7452 I'm still thinking about the best way to fix this. I could simply add another visitor to ensure that the moved expressions don't modify values being used in the condition, but I'm not totally happy with this due to the complexity. I therefore only documented it for now changelog: [`branches_sharing_code`] fixed false positive where block expressions would sometimes be ignored.
#7462 only documented this as a known issue. It's possible to actually fix this issue to not trigger the lint at all. I would keep this issue open until that is done, or it's decided that it's not worth it. You're welcome, thank you for the report. 🙃 |
Similar false positive happens when the shared code is locking. Moving lock to outside of if statement may cause different behaviour. |
I tried this code:
I expected to see this happen: I expected the lint to pass without a hitch, as the counter is used in the
if
statement.Instead, this happened:
I got a lint report, that I could change the if statements, as they all start with the same line of code, but doing that makes the code invalid.
Meta
cargo clippy -V
: clippy 0.1.53 (53cb7b0 2021-06-17)rustc -Vv
:The text was updated successfully, but these errors were encountered: