RS.CLIPPY.AS_POINTER_UNDERSCORE

Detects `as *mut _` and `as *const _` conversion

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

What it does

Checks for the usage of as *const _ or as *mut _ conversion using inferred type.

Why restrict this?

The conversion might include a dangerous cast that might go undetected due to the type being inferred.

Example

fn as_usize<T>(t: &T) -> usize {
    // BUG: `t` is already a reference, so we will here
    // return a dangling pointer to a temporary value instead
    &t as *const _ as usize
}

Use instead:

fn as_usize<T>(t: &T) -> usize {
    t as *const T as usize
}