-
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
False positive in cast_ptr_alignment #5618
Comments
Do you have a code example for this? |
So a minimal example would like this: let _ = (ptr as *const u8) as *const u64; This may be ok for
In (special) cases where you disagree with a lint, or have manually checked that a lint is not applicable, you should use IMO casts from u8 pointer is not a FP in general, but a special case where a cast to a more strictly aligned pointer is fine ➡️ |
because i want to add an offset in bytes. i honestly think this lint should be completely removed, clippy is not equiped to deal with this situation. im reasonably sure that this lint will also error on the standard library, for example in slice |
That's a fair point. I don't think we should remove it completely, but rather move it to pedantic |
i am not sure what further discussion is needed, i will open a pr. |
Thanks! I marked it as need-discussion, to have it over for some more opinions. But this was 10 days ago, so I think moving this is fine. |
if i cast a highly-aligned pointer to u8 to a mid-aligned pointer (in my case its 4096 -> 1 -> 8) clippy errors. this is wrong. there are many cases where casting from u8 is acceptable alignment-wise, including when you have manually checked that the alignment works out, statically or dynamically.
The text was updated successfully, but these errors were encountered: