-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[unnecessary_lazy_eval
]: don't lint on types with deref impl
#10864
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
r? @giraffate (rustbot has picked a reviewer for you, use r? to override) |
Yep, Gonna review it right 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.
LGTM, Thanks!
Yes, sorry for the delay. This looks good to me as well! Thank you! @bors r=blyxyas,xFrednet |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
consider autoderef through user-defined `Deref` in `eager_or_lazy` Fixes #10462 This PR handles autoderef in the `eager_or_lazy` util module and stops suggesting to change lazy to eager if autoderef in an expression goes through user defined `Deref` impls, e.g. ```rs struct S; impl Deref for S { type Target = (); fn deref(&self) -> &Self::Target { &() } } let _ = Some(()).as_ref().unwrap_or_else(|| &S); // autoderef `&S` -> `&()` ``` changelog: [`unnecessary_lazy_evaluations`]: don't suggest changing lazy evaluation to eager if autoderef goes through user-defined `Deref` r? `@xFrednet` (because of the earlier review in #10864, might help for context here)
Fixes #10437.
This PR changes clippy's util module
eager_or_lazy
to also consider deref expressions whose type has a non-builtin deref impl and not suggest replacing it as that might have observable side effects.A prominent example might be the
lazy_static
macro, which creates a newtype with aDeref
impl that you need to go through to get access to the inner value. Going from lazy to eager can make a difference there.changelog: [
unnecessary_lazy_eval
]: don't lint on types with non-builtin deref impl