-
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
New lint: deref coercions #7104
Comments
This sounds interesting, and I'd want to do it, any help on how I would do this though (sorry for naive question, this would be my first issue).
|
You can ping rustbot like In regards to implementing this, I'm not sure. I don't think implicit deref coercion is explicitly in the HIR (as a node) so unless there's a query for it you'd need to figure it out yourself, maybe there's some method to do that in PS: |
Perhaps this could use |
I hadn't thought of that; that sounds perfect for this |
You found the correct method 👍 |
@rustbot claim |
What it does
Lints on any use of deref coercions - for example, accessing a field or method through a
Deref
implCategories (optional)
What is the advantage of the recommended code over the original code
Normally, deref coercions are a very useful part of rust, making smart points like
Box
,Rc
,Ref
, andRefMut
much easier to use. However, this can be undesirable when writingunsafe
code, since a non-trivial function call could be completely hidden from view. For example:Vec::set_len
). A deref coercion might cause a panic at an unexpected point (due to a panicking user-suppliedDeref
impl), leading to undefined behavior.&self
reference behind what looks like a normal field access, leading to a very subtle form of undefined behavior.Drawbacks
This would be a fairly niche lint - unless you're writing
unsafe
code, there's little need to use it.Example
Could be written as:
The text was updated successfully, but these errors were encountered: