mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
76 lines
1.7 KiB
Rust
76 lines
1.7 KiB
Rust
// run-rustfix
|
|
|
|
#![allow(
|
|
clippy::cast_lossless,
|
|
// Int::max_value will be deprecated in the future
|
|
deprecated,
|
|
)]
|
|
#![warn(clippy::checked_conversions)]
|
|
|
|
use std::convert::TryFrom;
|
|
|
|
// Positive tests
|
|
|
|
// Signed to unsigned
|
|
|
|
pub fn i64_to_u32(value: i64) {
|
|
let _ = u32::try_from(value).is_ok();
|
|
let _ = u32::try_from(value).is_ok();
|
|
}
|
|
|
|
pub fn i64_to_u16(value: i64) {
|
|
let _ = u16::try_from(value).is_ok();
|
|
let _ = u16::try_from(value).is_ok();
|
|
}
|
|
|
|
pub fn isize_to_u8(value: isize) {
|
|
let _ = u8::try_from(value).is_ok();
|
|
let _ = u8::try_from(value).is_ok();
|
|
}
|
|
|
|
// Signed to signed
|
|
|
|
pub fn i64_to_i32(value: i64) {
|
|
let _ = i32::try_from(value).is_ok();
|
|
let _ = i32::try_from(value).is_ok();
|
|
}
|
|
|
|
pub fn i64_to_i16(value: i64) {
|
|
let _ = i16::try_from(value).is_ok();
|
|
let _ = i16::try_from(value).is_ok();
|
|
}
|
|
|
|
// Unsigned to X
|
|
|
|
pub fn u32_to_i32(value: u32) {
|
|
let _ = i32::try_from(value).is_ok();
|
|
let _ = i32::try_from(value).is_ok();
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
// Negative tests
|
|
|
|
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;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
pub fn i8_to_u8(value: i8) {
|
|
let _ = value >= 0;
|
|
}
|
|
|
|
fn main() {}
|