-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
suspicious_map: accept mutation in map().count()
#5375
Conversation
30b2400
to
02eec56
Compare
02eec56
to
fbca9f5
Compare
If the closure in the `map` call ends up mutating a variable, the call is assumed to no longer be suspicious. Given just a function name or path, there's no way to detect that there is interiour mutability, so the lint still fires in that case. However, it is now documented as a known problem. Fixes rust-lang#5253
fbca9f5
to
77d47e1
Compare
error: this call to `map()` won't have an effect on the call to `count()` | ||
--> $DIR/suspicious_map.rs:14:13 | ||
| | ||
LL | let _ = (0..3).map(ext_closure).count(); |
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.
Hm, this case still gets linted...
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.
All we get is the name of the function. Should we do name lookup and look into the implementation to check for mutated (non-local) variables?
Which makes me think…I suppose mutable local variables will false-negative this as well :/ . Hrm.
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.
Or can we do a name lookup and somehow ask if it is FnMut
?
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.
I was hoping, that maybe_body_owned_by
will get the BodyId
of the closure and that it would Just Work™ with mutable_variables
. Can you check if it even does get a BodyId
?
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.
It does get a BodyId
, but doesn't detect any mutated variables in it.
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.
So none of the examples in the test are Upvar
instances when going through mutated_variables
. I'm not sure what's going on here right now, but I suspect the Copy
-ness is confusing things here?
@mathstuf Sorry for taking so long for the review. I don't have an excuse, just wasn't really motivated to review PRs recently. Just wanted to let you know, that I didn't forgot about this and I'll try to find a solution for the remaining issue in the coming days. |
No problem :) . Thanks for the update. |
☔ The latest upstream changes (presumably #5763) made this pull request unmergeable. Please resolve the merge conflicts. |
I guess we can close this PR, as #6831 (based on this one) was merged recently |
If the closure in the
map
call ends up mutating a variable, the callis assumed to no longer be suspicious.
Given just a function name or path, there's no way to detect that there
is interiour mutability, so the lint still fires in that case. However,
it is now documented as a known problem.
Closes: #5253
Cc: @jpospychala @flip1995 @matthiaskrgr
changelog: