RS.CLIPPY.TRANSMUTE_INT_TO_NON_ZERO
Transmutes from an integer to a non-zero wrapper
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_int_to_non_zero. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for transmutes from T to NonZero<T>, and suggests the new_unchecked
method instead.
Why is this bad?
Transmutes work on any types and thus might cause unsoundness when those types change
elsewhere. new_unchecked only works for the appropriate types instead.
Example
let _: NonZero<u32> = unsafe { std::mem::transmute(123) };
Use instead:
let _: NonZero<u32> = unsafe { NonZero::new_unchecked(123) };