RS.CLIPPY.TRANSMUTE_PTR_TO_REF

Transmutes from a pointer to a reference type

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

What it does

Checks for transmutes from a pointer to a reference.

Why is this bad?

This can always be rewritten with & and *.

Known problems

  • mem::transmute in statics and constants is stable from Rust 1.46.0, while dereferencing raw pointer is not stable yet. If you need to do this in those places, you would have to use transmute instead.

Example

unsafe {
    let _: &T = std::mem::transmute(p); // where p: *const T
}

// can be written:
let _: &T = &*p;

Configuration

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)