-
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
add option_as_ref_deref
lint
#4945
Conversation
I found a case where the lint gives a bad suggestion.
This suggestion won't work because the type of |
I knew deref coercion would screw me over somewhere, should've created a test for that myself, thanks for noticing. I thought coercion is already explicit in hir but I guess it is not? |
Maybe we can check the type of |
@flip1995 I am a little puzzled with getting |
I think you can just check if Here is my reasoning...
|
@mikerite That was my reasoning as well when I was implementing it. Currently I am checking whether the first argument to |
☔ The latest upstream changes (presumably #4885) made this pull request unmergeable. Please resolve the merge conflicts. |
Try the |
I'm not sure myself. Somehow get the |
d9720d5
to
db0a3a6
Compare
I presumably fixed it, can anybody think of any more tests to add? |
A macro test would be good |
☔ The latest upstream changes (presumably #4973) made this pull request unmergeable. Please resolve the merge conflicts. |
Maybe |
☔ The latest upstream changes (presumably #4543) made this pull request unmergeable. Please resolve the merge conflicts. |
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 just realized, that I reviewed this PR weeks ago, but never pressed "Submit review". Sorry for the long wait time...
clippy_lints/src/methods/mod.rs
Outdated
span_lint_and_then(cx, OPTION_AS_REF_DEREF, expr.span, &msg, |db| { | ||
db.span_suggestion(expr.span, &suggestion, hint, Applicability::MachineApplicable); | ||
}); |
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.
Why not just span_lint_and_sugg
? Everything else LGTM.
Lets merge this for now, I'll probably add |
@bors r+ |
📌 Commit 796958c has been approved by |
add `option_as_ref_deref` lint changelog: add a new lint that lints `option.as_ref().map(Deref::deref)` (and similar calls), which could be expressed more succinctly as `option.as_deref[_mut]()`. Closes #4918.
☀️ Test successful - checks-travis, status-appveyor |
Is this being tracked anywhere? That's how I tend to write this case. |
Good catch! It is now: #5367 |
changelog: add a new lint that lints
option.as_ref().map(Deref::deref)
(and similar calls), which could be expressed more succinctly asoption.as_deref[_mut]()
. Closes #4918.