-
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
clippy::drop_ref will trigger on &mut T
as well as &T
#4461
Comments
I ran into this today. :-/ |
In one sense, dropping an On the other hand, |
I think keeping this lint enabled by default for For example, I talked with @luser about the case he mentioned above, and it turned out that the lint was correct: the |
I ran into this and still think it's useful for reasons beyond just being an assertion, but it's possible I'm misunderstanding something (I am pretty new to rust), but if I am misunderstanding something it might be worth documenting what is wrong with my reasoning for other newbies who come across this. Rust requires that you only have one mutable reference at a time to a given object. If you are writing unsafe code, it's definitely possible to write code that violates this language rule. To avoid violating the language rule you may choose to explicitly drop a mutable reference early. Imagine:
If it is possible for |
Under non-lexical lifetimes, a reference is only "live" until the point where it is last used. You don't need to explicitly So the |
Is there a future where this is changed? This issue was re-opened and remains that way, so adding my +1 to it. I am in the mixed reference and pointer scenario, and the drop complements an unsafe block:
It's nice to see the SAFETY comment explicitly supported in code. The code is already mentally taxing, and adding clippy attributes detracts from the clarity of the relationship. Would it make sense to issue the warning when the reference is a function parameter, but permit it otherwise? Since parameters are noalias ("protected" in stacked/tree borrow parlance), dropping them can never help static assert why some following code is safe. |
the
drop_ref
lint will trigger on&mut T
values being dropped, even though dropping them does have an effect.The text was updated successfully, but these errors were encountered: