RS.CLIPPY.TRANSMUTE_PTR_TO_PTR

Transmutes from a pointer to a pointer / a reference to a reference

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_ptr_to_ptr. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for transmutes from a pointer to a pointer, or from a reference to a reference.

Why is this bad?

Transmutes are dangerous, and these can instead be written as casts.

Example

let ptr = &1u32 as *const u32;
unsafe {
    // pointer-to-pointer transmute
    let _: *const f32 = std::mem::transmute(ptr);
    // ref-ref transmute
    let _: &f32 = std::mem::transmute(&1u32);
}
// These can be respectively written:
let _ = ptr as *const f32;
let _ = unsafe{ &*(&1u32 as *const u32 as *const f32) };