RS.CLIPPY.MANUAL_DANGLING_PTR
Casting small constant literals to pointers to create dangling pointers
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: manual_dangling_ptr. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for casts of small constant literals or mem::align_of results to raw pointers.
Why is this bad?
This creates a dangling pointer and is better expressed as
{std, core}::ptr::{dangling, dangling_mut}.
Example
let ptr = 4 as *const u32;
let aligned = std::mem::align_of::<u32>() as *const u32;
let mut_ptr: *mut i64 = 8 as *mut _;
Use instead:
let ptr = std::ptr::dangling::<u32>();
let aligned = std::ptr::dangling::<u32>();
let mut_ptr: *mut i64 = std::ptr::dangling_mut();