RS.CLIPPY.TRANSMUTE_UNDEFINED_REPR
Transmute to or from a type with an undefined representation
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: transmute_undefined_repr. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for transmutes between types which do not have a representation defined relative to each other.
Why is this bad?
The results of such a transmute are not defined.
Known problems
This lint has had multiple problems in the past and was moved to nursery. See issue
#8496 for more details.
Example
struct Foo<T>(u32, T);
let _ = unsafe { core::mem::transmute::<Foo<u32>, Foo<i32>>(Foo(0u32, 0u32)) };
Use instead:
#[repr(C)]
struct Foo<T>(u32, T);
let _ = unsafe { core::mem::transmute::<Foo<u32>, Foo<i32>>(Foo(0u32, 0u32)) };