2020-08-28 14:10:16 +00:00
|
|
|
#![warn(clippy::transmute_float_to_int)]
|
2024-02-19 13:53:53 +00:00
|
|
|
#![allow(clippy::missing_transmute_annotations)]
|
2019-12-08 00:59:17 +00:00
|
|
|
|
|
|
|
fn float_to_int() {
|
|
|
|
let _: u32 = unsafe { std::mem::transmute(1f32) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `f32` to a `u32`
|
|
|
|
//~| NOTE: `-D clippy::transmute-float-to-int` implied by `-D warnings`
|
2019-12-08 00:59:17 +00:00
|
|
|
let _: i32 = unsafe { std::mem::transmute(1f32) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `f32` to a `i32`
|
2019-12-08 00:59:17 +00:00
|
|
|
let _: u64 = unsafe { std::mem::transmute(1f64) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `f64` to a `u64`
|
2019-12-08 00:59:17 +00:00
|
|
|
let _: i64 = unsafe { std::mem::transmute(1f64) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `f64` to a `i64`
|
2019-12-08 00:59:17 +00:00
|
|
|
let _: u64 = unsafe { std::mem::transmute(1.0) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `f64` to a `u64`
|
2019-12-08 00:59:17 +00:00
|
|
|
let _: u64 = unsafe { std::mem::transmute(-1.0) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `f64` to a `u64`
|
2019-12-08 00:59:17 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 14:10:16 +00:00
|
|
|
mod issue_5747 {
|
|
|
|
const VALUE32: i32 = unsafe { std::mem::transmute(1f32) };
|
|
|
|
const VALUE64: u64 = unsafe { std::mem::transmute(1f64) };
|
|
|
|
|
|
|
|
const fn to_bits_32(v: f32) -> u32 {
|
|
|
|
unsafe { std::mem::transmute(v) }
|
|
|
|
}
|
|
|
|
|
|
|
|
const fn to_bits_64(v: f64) -> i64 {
|
|
|
|
unsafe { std::mem::transmute(v) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-08 00:59:17 +00:00
|
|
|
fn main() {}
|