pub static PTR_TO_INTEGER_TRANSMUTE_IN_CONSTS: &'static Lint
Expand description
The ptr_to_integer_transmute_in_consts
lint detects pointer to integer
transmute in const functions and associated constants.
§Example
const fn foo(ptr: *const u8) -> usize {
unsafe {
std::mem::transmute::<*const u8, usize>(ptr)
}
}
{{produces}}
§Explanation
Transmuting pointers to integers in a const
context is undefined behavior.
Any attempt to use the resulting integer will abort const-evaluation.
But sometimes the compiler might not emit an error for pointer to integer transmutes inside const functions and associated consts because they are evaluated only when referenced. Therefore, this lint serves as an extra layer of defense to prevent any undefined behavior from compiling without any warnings or errors.
See std::mem::transmute in the reference for more details.