Skip to content

feat: lint against transmute int to ptr #13192

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

csmoe
Copy link
Member

@csmoe csmoe commented Jul 31, 2024

fixes #13140

changelog: make [wrong_transmute] lint cover transmute_int2ptr

@rustbot
Copy link
Collaborator

rustbot commented Jul 31, 2024

r? @dswij

rustbot has assigned @dswij.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 31, 2024
@csmoe csmoe force-pushed the fix/transmute-int-to-ptr branch 2 times, most recently from f00f10a to f10e731 Compare July 31, 2024 06:56
@csmoe csmoe force-pushed the fix/transmute-int-to-ptr branch from f10e731 to ee73189 Compare July 31, 2024 08:53
@csmoe csmoe marked this pull request as draft July 31, 2024 09:50
Comment on lines +1 to +8
error: transmute from a `usize` to a pointer
--> tests/ui/transmute_int_to_ptr.rs:11:22
|
LL | let x = unsafe { std::mem::transmute::<K1, *mut i8>(k) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::wrong-transmute` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::wrong_transmute)]`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a new lint with more specific diagnostics mentioning that it's UB to dereference the pointer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

new lint: pointer created from transmuting an int into a pointer is not able to be dereferenced
4 participants