RS.CLIPPY.BORROW_AS_PTR
Borrowing just to cast to a raw 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: borrow_as_ptr. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for the usage of &expr as *const T or
&mut expr as *mut T, and suggest using &raw const or
&raw mut instead.
Why is this bad?
This would improve readability and avoid creating a reference
that points to an uninitialized value or unaligned place.
Read the &raw explanation in the Reference for more information.
Example
let val = 1;
let p = &val as *const i32;
let mut val_mut = 1;
let p_mut = &mut val_mut as *mut i32;
Use instead:
let val = 1;
let p = &raw const val;
let mut val_mut = 1;
let p_mut = &raw mut val_mut;
Configuration
-
msrv: The minimum rust version that the project supports. Defaults to therust-versionfield inCargo.toml(default:
current version)