RS.CLIPPY.REF_AS_PTR

Using `as` to cast a reference to pointer

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: ref_as_ptr. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for casts of references to pointer using as and suggests std::ptr::from_ref and std::ptr::from_mut instead.

Why is this bad?

Using as casts may result in silently changing mutability or type.

Example

let a_ref = &1;
let a_ptr = a_ref as *const _;

Use instead:

let a_ref = &1;
let a_ptr = std::ptr::from_ref(a_ref);