Skip to content

Conversation

@mendelsshop
Copy link

@mendelsshop mendelsshop commented Oct 31, 2025

Checks transmutes between the same ADT, making sure type arguments don't go from &T to &mut T.

Like it would catch something like:

let _: Option<&mut i32> = std::mem::transmute(Some(&5i32));

changelog: new lint [mutable_adt_argument_transmute]

fixes #372

@mendelsshop mendelsshop force-pushed the catch_adt_mut_transmut branch 2 times, most recently from 4d4c366 to 61c208c Compare October 31, 2025 02:38
@mendelsshop mendelsshop force-pushed the catch_adt_mut_transmut branch 2 times, most recently from 8b63f22 to cbe29ff Compare October 31, 2025 03:28
@mendelsshop mendelsshop changed the title add lint for transmute from &T to &mut T of a ADT arguement (WIP) add lint for transmute from &T to &mut T of a ADT argument (WIP) Oct 31, 2025
@mendelsshop mendelsshop force-pushed the catch_adt_mut_transmut branch from cbe29ff to 27d8267 Compare October 31, 2025 03:30
@mendelsshop mendelsshop force-pushed the catch_adt_mut_transmut branch from 27d8267 to fb142f2 Compare October 31, 2025 03:31
@mendelsshop
Copy link
Author

The way I am doing it now, I take the from_ty and to_ty and just zip the ty.walk() of both of them, which leads to potential false positive like catching:

let _: Result<Option<&mut f32>, &usize> = std::mem::transmute(Option::<Result<&f32, usize>>::Some(Ok(&2f32)));

Because in the order of the walk() &mut f32 and &f32 are at the same position in their respective walk().

@mendelsshop mendelsshop changed the title add lint for transmute from &T to &mut T of a ADT argument (WIP) add lint for transmute from &T to &mut T of a ADT argument Oct 31, 2025
@mendelsshop mendelsshop marked this pull request as ready for review October 31, 2025 14:55
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 31, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2025

r? @y21

rustbot has assigned @y21.
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp 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.

Catch transmuting Option<&T> to Option<&mut T>

3 participants