-
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
Lint to disallow using as
for pointer casts in favor of .cast()
#5890
Comments
There's a lint that seems to lint on |
Yes, and there are also lints for specific types of as casts. There is no lint for specifically pointer casts while still allowing other kinds of as casts. |
This would seem to affect the |
It seems to me this lint has already suggested twice (#4065 and #4708 (comment)). Maybe 4065 can be closed since 5890 has a bit more details. |
Add a note to `as_conversions` I have seen a couple of examples where there are some misunderstandings of `as_conversions` ([1](#5890 (comment)), [2](#6116 (comment)) and [3](#6428)). This PR adds the note that explains its purpose and relationship with other `as` related casts. Open question: should I list every related lints for discoverbility, or just suggest how to find these? I chose the former because there's no way to list only and all `as` related lints (e.g. on All the Clippt Lints, 'cast' includes some noises, but `cast_` excludes some) even though I cannot guarantee the list will be updated to include future changes. --- changelog: Add a note to the document of `as_conversions`
What it does
Any raw pointer cast from
*const T
to*const U
or*mut T
to*mut U
that usesas
should be caught by this lint. Instead you should use.cast()
.Should probably be a pedantic lint.
Drawbacks
None.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: