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
[map_unwrap_or
]: don't lint when referenced variable is moved
#10919
Conversation
r? @xFrednet (rustbot has picked a reviewer for you, use r? to override) |
Hey @blyxyas, this looks like another good PR if you want to review it. If you're busy rn, I'm also happy to do the entire review :) |
You understimate me, I may be just out of the hospital, but gimme that bad boi! Clippy 👏 comes 👏 first |
Just making sure, I basically no-lifed Clippy at the start, and only later learned that you need a break every once in a while. That being said, I've no-lifing another project rn again, so it's all back to normal xD |
@xFrednet I'm sorry but I don't think I can do the full review. If this is urgent, could you review it? If not, I think we'll have to wait a day or two until I can come back to seeing letters and colors in my screen. |
@blyxyas No worries at all, rest 👏 comes 👏 first! Generally speaking, it's totally fine, to let PRs wait on a review for a bit. I usually try to get to every one within 5 days, but even a week is not a problem. If you know that it'll take time, it's always good to let the author know, but there are no real time-critical issues in Clippy. The changes would need to wait until the next sync anyways. I've already reviewed some PRs today, and will look at this over the next few days. If you want to pick up the review, when you feel better, you're very welcome. I appreciate you being honest! You can delete that part from your message if you feel it's too personal. Anxiety can suck so much..., if you have any questions, need reassurance or anything, you can always reach out on Zulip as well! @y21 Sorry, for hijacking the PR comments for this discussion. You'll get a review in the next couple of days :D |
it's all good, i won't be home this weekend anyways, so take your time :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks, pretty hard issue to solve ❤️
cc @xFrednet
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #10579.
The previous way of checking if changing
map(f).unwrap_or(a)
tomap_or(a, f)
is safe had a flaw when the argument tounwrap_or
moves a binding and themap
closure references that binding in some way.It used to simply check if any of the identifiers in the
unwrap_or
argument are referenced in themap
closure, but it didn't consider the case where the moved binding is referred to through references, for example:This compiles as is, but we cannot change it to
map_or
. This lint however did suggest changing it, because the simple way of checking ifx
is referenced anywhere in themap
closure fails here. The safest thing to do here imo (what this PR does) is check if the moved valuex
is referenced anywhere in the body (before theunwrap_or
call). One can always create a reference to the value and smuggle them into the closure, without actually referring tox
. The original, linked issue shows another one such example:x.strip_suffix(&[0])
creates a reference tox
that is available throughs
inside of themap
closure, so we can't change it tomap_or
.changelog: [
map_unwrap_or
]: don't lint when referenced variable is moved