-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix map_unwrap_or fail to cover Result::unwrap_or
#15718
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
Conversation
|
Lintcheck changes for 0db25db
This comment will be updated if you push new changes |
|
Unless you have a good reason not to, please use |
d89877a to
b08fb14
Compare
|
Moved. Thank you! |
b08fb14 to
6375703
Compare
This comment has been minimized.
This comment has been minimized.
|
Also fixes #15713 |
0b7431e to
48b8dd9
Compare
|
Also closes #15752 |
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.
If possible, you should squash together the two commits "Apply map_unwrap to Clippy itself" and make it the first commit). This way, after every commit, Clippy tests still pass (including dogfood), and it makes it easy to bisect should something go wrong. Then each "fix" commit can be put on top.
48b8dd9 to
761ecf0
Compare
|
Updated. Thank you |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
r? clippy |
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.
Could you also squash the commits please? The current separation makes it harder to read and review.
0a176fc to
081f15f
Compare
|
r? clippy |
|
r? clippy |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Also closes #16258 |
| // So, we have to check that `a` is not referenced anywhere (even outside of the `.map` closure!) | ||
| // before the call to `unwrap_or`. | ||
|
|
||
| let mut unwrap_visitor = UnwrapVisitor { |
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 think these two are simple enough that we can just use the for_each_expr helper. And, can we add a comment here?
| && let Node::Pat(pat) = self.cx.tcx.hir_node(local_id) | ||
| && let PatKind::Binding(_, local_id, ..) = pat.kind |
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.
What does this part fix? When will this not be a PatKind::Binding, and why?
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'm not sure about this too.
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.
If you look into the issues this PR is addressing, all the changes in map_unwrap_or.rs, wrongly showed as additions, are actually the implementation from option_map_unwrap_or.rs, which is renamed to this file now.
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.
For this reason, I prefer to leave these implementation details as is, while just focusing reorganizing the map_unwrap_or and map_unwrap_or_else two lints in this PR.
| type NestedFilter = nested_filter::All; | ||
| type Result = ControlFlow<()>; | ||
| fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'_>) -> ControlFlow<()> { | ||
| // If we haven't found a reference yet, check if this references |
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.
| // If we haven't found a reference yet, check if this references | |
| // Check if this references |
This more so implies that the previous UnwrapVisitor checks for references, not this code. I was a bit confused last review.
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 think we just need more tests in general. To be specific, cases where it doesn't lint, like for when unwrap_arg is referenced. Same with the mutable borrows case.
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.
Ookay, looking at it again, that's not all that's in this file. So +1 from me.
| fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'_>) -> ControlFlow<()> { | ||
| // If we haven't found a reference yet, check if this references | ||
| // one of the locals that was moved in the `unwrap_or` argument. | ||
| // We are only interested in exprs that appear before the `unwrap_or` call. |
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.
We are only interested in exprs that appear before the
unwrap_orcall.
Why is that? Does the borrowck error not happen in that case?
|
Ok, hadn't noticed, that's fair. I'll do one final look tomorrow and then probably merge 👍 |
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.
Ookay, looking at it again, that's not all that's in this file. So +1 from me.
|
cc @samueltardieu, this look good to you? You previously requested changes. |
Yes, my points have been addressed. I'll merge since you +1'ed. |
Closes #15713
Closes #15714
Closes #15752
Closes #16258
changelog: [
map_unwrap_or] add cover forResult::unwrap_or