add lint for transmute from &T to &mut T of a ADT argument
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 rust-lang/rust-clippy#372
Edit:
I now skip the parts that don't match (like Option<_> and Result<_, _>), but this does require me to match on each type's .kind() to see if they are the same ADT, slice, ..., and if not I use skip_current_subtree().
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().
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
No changes for 1cc591ccd7e895436d9baae8ecec6578daca8ebf
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.
Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.
r? clippy
r? clippy