2023-02-16 15:08:28 +00:00
|
|
|
#![warn(clippy::transmute_int_to_non_zero)]
|
2024-02-19 13:53:53 +00:00
|
|
|
#![allow(clippy::missing_transmute_annotations)]
|
2023-02-16 15:08:28 +00:00
|
|
|
|
|
|
|
use core::num::*;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let int_u8: u8 = 1;
|
|
|
|
let int_u16: u16 = 1;
|
|
|
|
let int_u32: u32 = 1;
|
|
|
|
let int_u64: u64 = 1;
|
|
|
|
let int_u128: u128 = 1;
|
|
|
|
|
|
|
|
let int_i8: i8 = 1;
|
|
|
|
let int_i16: i16 = 1;
|
|
|
|
let int_i32: i32 = 1;
|
|
|
|
let int_i64: i64 = 1;
|
|
|
|
let int_i128: i128 = 1;
|
|
|
|
|
|
|
|
let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `u8` to a `NonZeroU8`
|
|
|
|
//~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings`
|
2023-02-16 15:08:28 +00:00
|
|
|
let _: NonZeroU16 = unsafe { std::mem::transmute(int_u16) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `u16` to a `NonZeroU16`
|
2023-02-16 15:08:28 +00:00
|
|
|
let _: NonZeroU32 = unsafe { std::mem::transmute(int_u32) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `u32` to a `NonZeroU32`
|
2023-02-16 15:08:28 +00:00
|
|
|
let _: NonZeroU64 = unsafe { std::mem::transmute(int_u64) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `u64` to a `NonZeroU64`
|
2023-02-16 15:08:28 +00:00
|
|
|
let _: NonZeroU128 = unsafe { std::mem::transmute(int_u128) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `u128` to a `NonZeroU128`
|
2023-02-16 15:08:28 +00:00
|
|
|
|
|
|
|
let _: NonZeroI8 = unsafe { std::mem::transmute(int_i8) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `i8` to a `NonZeroI8`
|
2023-02-16 15:08:28 +00:00
|
|
|
let _: NonZeroI16 = unsafe { std::mem::transmute(int_i16) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `i16` to a `NonZeroI16`
|
2023-02-16 15:08:28 +00:00
|
|
|
let _: NonZeroI32 = unsafe { std::mem::transmute(int_i32) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `i32` to a `NonZeroI32`
|
2023-02-16 15:08:28 +00:00
|
|
|
let _: NonZeroI64 = unsafe { std::mem::transmute(int_i64) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `i64` to a `NonZeroI64`
|
2023-02-16 15:08:28 +00:00
|
|
|
let _: NonZeroI128 = unsafe { std::mem::transmute(int_i128) };
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: transmute from a `i128` to a `NonZeroI128`
|
2023-02-16 15:08:28 +00:00
|
|
|
|
|
|
|
let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) };
|
|
|
|
let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) };
|
|
|
|
let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) };
|
|
|
|
let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) };
|
|
|
|
let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) };
|
|
|
|
|
|
|
|
let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) };
|
|
|
|
let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) };
|
|
|
|
let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) };
|
|
|
|
let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) };
|
|
|
|
let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) };
|
|
|
|
}
|