2020-08-28 09:10:16 -05:00
|
|
|
#![warn(clippy::transmute_float_to_int)]
|
2024-04-04 12:52:55 -05:00
|
|
|
#![allow(clippy::missing_transmute_annotations)]
|
2024-10-04 10:43:27 -05:00
|
|
|
#![feature(f128)]
|
|
|
|
#![feature(f16)]
|
2019-12-07 18:59:17 -06:00
|
|
|
|
|
|
|
fn float_to_int() {
|
|
|
|
let _: u32 = unsafe { std::mem::transmute(1f32) };
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: transmute from a `f32` to a `u32`
|
|
|
|
//~| NOTE: `-D clippy::transmute-float-to-int` implied by `-D warnings`
|
2019-12-07 18:59:17 -06:00
|
|
|
let _: i32 = unsafe { std::mem::transmute(1f32) };
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: transmute from a `f32` to a `i32`
|
2019-12-07 18:59:17 -06:00
|
|
|
let _: u64 = unsafe { std::mem::transmute(1f64) };
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: transmute from a `f64` to a `u64`
|
2019-12-07 18:59:17 -06:00
|
|
|
let _: i64 = unsafe { std::mem::transmute(1f64) };
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: transmute from a `f64` to a `i64`
|
2019-12-07 18:59:17 -06:00
|
|
|
let _: u64 = unsafe { std::mem::transmute(1.0) };
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: transmute from a `f64` to a `u64`
|
2019-12-07 18:59:17 -06:00
|
|
|
let _: u64 = unsafe { std::mem::transmute(-1.0) };
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: transmute from a `f64` to a `u64`
|
2019-12-07 18:59:17 -06:00
|
|
|
}
|
|
|
|
|
2020-08-28 09:10:16 -05:00
|
|
|
mod issue_5747 {
|
2024-06-18 12:34:49 -05:00
|
|
|
const VALUE16: i16 = unsafe { std::mem::transmute(1f16) };
|
2024-08-25 08:15:15 -05:00
|
|
|
//~^ ERROR: transmute from a `f16` to a `i16`
|
2020-08-28 09:10:16 -05:00
|
|
|
const VALUE32: i32 = unsafe { std::mem::transmute(1f32) };
|
2024-08-25 08:15:15 -05:00
|
|
|
//~^ ERROR: transmute from a `f32` to a `i32`
|
2020-08-28 09:10:16 -05:00
|
|
|
const VALUE64: u64 = unsafe { std::mem::transmute(1f64) };
|
2024-08-25 08:15:15 -05:00
|
|
|
//~^ ERROR: transmute from a `f64` to a `u64`
|
2024-06-18 12:34:49 -05:00
|
|
|
const VALUE128: u128 = unsafe { std::mem::transmute(1f128) };
|
2024-08-25 08:15:15 -05:00
|
|
|
//~^ ERROR: transmute from a `f128` to a `u128`
|
2024-06-18 12:34:49 -05:00
|
|
|
|
|
|
|
const fn to_bits_16(v: f16) -> u16 {
|
|
|
|
unsafe { std::mem::transmute(v) }
|
2024-08-25 08:15:15 -05:00
|
|
|
//~^ ERROR: transmute from a `f16` to a `u16`
|
2024-06-18 12:34:49 -05:00
|
|
|
}
|
2020-08-28 09:10:16 -05:00
|
|
|
|
|
|
|
const fn to_bits_32(v: f32) -> u32 {
|
|
|
|
unsafe { std::mem::transmute(v) }
|
2024-08-25 08:15:15 -05:00
|
|
|
//~^ ERROR: transmute from a `f32` to a `u32`
|
2020-08-28 09:10:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const fn to_bits_64(v: f64) -> i64 {
|
|
|
|
unsafe { std::mem::transmute(v) }
|
2024-08-25 08:15:15 -05:00
|
|
|
//~^ ERROR: transmute from a `f64` to a `i64`
|
2020-08-28 09:10:16 -05:00
|
|
|
}
|
2024-06-18 12:34:49 -05:00
|
|
|
|
|
|
|
const fn to_bits_128(v: f128) -> i128 {
|
|
|
|
unsafe { std::mem::transmute(v) }
|
2024-08-25 08:15:15 -05:00
|
|
|
//~^ ERROR: transmute from a `f128` to a `i128`
|
2024-06-18 12:34:49 -05:00
|
|
|
}
|
2020-08-28 09:10:16 -05:00
|
|
|
}
|
|
|
|
|
2019-12-07 18:59:17 -06:00
|
|
|
fn main() {}
|