2020-06-02 21:04:24 -05:00
|
|
|
#![allow(
|
|
|
|
clippy::cast_lossless,
|
2023-06-20 16:34:24 -05:00
|
|
|
clippy::legacy_numeric_constants,
|
2022-10-21 16:35:39 -05:00
|
|
|
unused,
|
2020-06-02 21:04:24 -05:00
|
|
|
// Int::max_value will be deprecated in the future
|
|
|
|
deprecated,
|
|
|
|
)]
|
2019-05-14 13:05:27 -05:00
|
|
|
#![warn(clippy::checked_conversions)]
|
2020-06-02 21:04:24 -05:00
|
|
|
|
2019-05-14 13:05:27 -05:00
|
|
|
// Positive tests
|
|
|
|
|
|
|
|
// Signed to unsigned
|
|
|
|
|
2020-06-02 21:04:24 -05:00
|
|
|
pub fn i64_to_u32(value: i64) {
|
|
|
|
let _ = u32::try_from(value).is_ok();
|
|
|
|
let _ = u32::try_from(value).is_ok();
|
2019-05-14 13:05:27 -05:00
|
|
|
}
|
|
|
|
|
2020-06-02 21:04:24 -05:00
|
|
|
pub fn i64_to_u16(value: i64) {
|
|
|
|
let _ = u16::try_from(value).is_ok();
|
|
|
|
let _ = u16::try_from(value).is_ok();
|
2019-05-14 13:05:27 -05:00
|
|
|
}
|
|
|
|
|
2020-06-02 21:04:24 -05:00
|
|
|
pub fn isize_to_u8(value: isize) {
|
|
|
|
let _ = u8::try_from(value).is_ok();
|
|
|
|
let _ = u8::try_from(value).is_ok();
|
2019-05-14 13:05:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Signed to signed
|
|
|
|
|
2020-06-02 21:04:24 -05:00
|
|
|
pub fn i64_to_i32(value: i64) {
|
|
|
|
let _ = i32::try_from(value).is_ok();
|
|
|
|
let _ = i32::try_from(value).is_ok();
|
2019-05-14 13:05:27 -05:00
|
|
|
}
|
|
|
|
|
2020-06-02 21:04:24 -05:00
|
|
|
pub fn i64_to_i16(value: i64) {
|
|
|
|
let _ = i16::try_from(value).is_ok();
|
|
|
|
let _ = i16::try_from(value).is_ok();
|
2019-05-14 13:05:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unsigned to X
|
|
|
|
|
2020-06-02 21:04:24 -05:00
|
|
|
pub fn u32_to_i32(value: u32) {
|
|
|
|
let _ = i32::try_from(value).is_ok();
|
|
|
|
let _ = i32::try_from(value).is_ok();
|
2019-05-14 13:05:27 -05:00
|
|
|
}
|
|
|
|
|
2020-06-02 21:04:24 -05:00
|
|
|
pub fn usize_to_isize(value: usize) {
|
|
|
|
let _ = isize::try_from(value).is_ok() && value as i32 == 5;
|
|
|
|
let _ = isize::try_from(value).is_ok() && value as i32 == 5;
|
2019-05-14 13:05:27 -05:00
|
|
|
}
|
|
|
|
|
2020-06-02 21:04:24 -05:00
|
|
|
pub fn u32_to_u16(value: u32) {
|
|
|
|
let _ = u16::try_from(value).is_ok() && value as i32 == 5;
|
|
|
|
let _ = u16::try_from(value).is_ok() && value as i32 == 5;
|
2019-05-14 13:05:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Negative tests
|
|
|
|
|
2020-06-02 21:04:24 -05:00
|
|
|
pub fn no_i64_to_i32(value: i64) {
|
|
|
|
let _ = value <= (i32::max_value() as i64) && value >= 0;
|
|
|
|
let _ = value <= (i32::MAX as i64) && value >= 0;
|
2019-05-14 13:05:27 -05:00
|
|
|
}
|
|
|
|
|
2020-06-02 21:04:24 -05:00
|
|
|
pub fn no_isize_to_u8(value: isize) {
|
|
|
|
let _ = value <= (u8::max_value() as isize) && value >= (u8::min_value() as isize);
|
|
|
|
let _ = value <= (u8::MAX as isize) && value >= (u8::MIN as isize);
|
2019-05-14 13:05:27 -05:00
|
|
|
}
|
|
|
|
|
2020-06-02 21:04:24 -05:00
|
|
|
pub fn i8_to_u8(value: i8) {
|
|
|
|
let _ = value >= 0;
|
2019-05-14 13:05:27 -05:00
|
|
|
}
|
|
|
|
|
2022-05-28 00:33:06 -05:00
|
|
|
// Do not lint
|
|
|
|
pub const fn issue_8898(i: u32) -> bool {
|
|
|
|
i <= i32::MAX as u32
|
|
|
|
}
|
|
|
|
|
2022-11-19 06:50:02 -06:00
|
|
|
#[clippy::msrv = "1.33"]
|
2022-10-21 16:35:39 -05:00
|
|
|
fn msrv_1_33() {
|
|
|
|
let value: i64 = 33;
|
|
|
|
let _ = value <= (u32::MAX as i64) && value >= 0;
|
|
|
|
}
|
|
|
|
|
2022-11-19 06:50:02 -06:00
|
|
|
#[clippy::msrv = "1.34"]
|
2022-10-21 16:35:39 -05:00
|
|
|
fn msrv_1_34() {
|
|
|
|
let value: i64 = 34;
|
|
|
|
let _ = u32::try_from(value).is_ok();
|
|
|
|
}
|
|
|
|
|
2019-05-14 13:05:27 -05:00
|
|
|
fn main() {}
|