-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 against transmutes which could be as
casts.
#34249
Comments
Unnecessary transmutes are so common that I would encourage making this a warning lint in rustc itself. It could really help to cut down on the number of transmutes in the crates.io ecosystem. Having transmutes when they aren't actually doing things that require transmute leads to a boy-who-cried-wolf problem, making people easily miss transmutes that are more dangerous. |
AFAIK Clippy doesn't have this yet, although |
Clippy also has |
@mcarton To clarify, with "between pointers and integers" I meant casts that can be done with |
Triage: no changes |
Related to this: #34609 added documentation to
cc @y86-dev |
Copying my comment from Zulip: The context I remember around the original PR, all those years ago: at the time, there was a lot of anxiety around unnecessary unsafe usage. The short and long of it was roughly "as is safe, transmute is unsafe, we should be encouraging use of as where possible." I also think that since all those years ago, as's favorability has gone down, and tolerance for unsafe has gone up a little, so I'm not even sure that the original justification would still be a good one today. |
The relevant casts are at least those between pointers and integers, or between two pointers.
There's probably also some likelihood of same-type transmutes arising, which keep working after changing the types (of FFI signatures, for example) but could be removed because they're noops.
Clippy might be interested, if they don't already have this (cc @Manishearth).
The text was updated successfully, but these errors were encountered: