2023-10-14 22:57:33 +00:00
|
|
|
#![warn(clippy::unnecessary_fallible_conversions)]
|
|
|
|
|
|
|
|
fn main() {
|
2024-01-01 17:23:44 +00:00
|
|
|
// --- TryFromMethod `T::try_from(u)` ---
|
|
|
|
|
2023-10-14 22:57:33 +00:00
|
|
|
let _: i64 = 0i32.try_into().unwrap();
|
2024-01-01 17:23:44 +00:00
|
|
|
//~^ ERROR: use of a fallible conversion when an infallible one could be used
|
|
|
|
|
2023-10-14 22:57:33 +00:00
|
|
|
let _: i64 = 0i32.try_into().expect("can't happen");
|
2024-01-01 17:23:44 +00:00
|
|
|
//~^ ERROR: use of a fallible conversion when an infallible one could be used
|
|
|
|
|
|
|
|
// --- TryFromFunction `T::try_from(U)` ---
|
2024-01-01 08:17:46 +00:00
|
|
|
|
|
|
|
let _ = i64::try_from(0i32).unwrap();
|
2024-01-01 17:23:44 +00:00
|
|
|
//~^ ERROR: use of a fallible conversion when an infallible one could be used
|
|
|
|
|
2024-01-01 08:17:46 +00:00
|
|
|
let _ = i64::try_from(0i32).expect("can't happen");
|
2024-01-01 17:23:44 +00:00
|
|
|
//~^ ERROR: use of a fallible conversion when an infallible one could be used
|
|
|
|
|
|
|
|
// --- TryIntoFunction `U::try_into(t)` ---
|
2024-01-01 08:17:46 +00:00
|
|
|
|
|
|
|
let _: i64 = i32::try_into(0).unwrap();
|
2024-01-01 17:23:44 +00:00
|
|
|
//~^ ERROR: use of a fallible conversion when an infallible one could be used
|
|
|
|
|
2024-01-01 08:17:46 +00:00
|
|
|
let _: i64 = i32::try_into(0i32).expect("can't happen");
|
2024-01-01 17:23:44 +00:00
|
|
|
//~^ ERROR: use of a fallible conversion when an infallible one could be used
|
|
|
|
|
|
|
|
// --- TryFromFunction `<T as TryFrom<U>>::try_from(U)` ---
|
2024-01-01 08:17:46 +00:00
|
|
|
|
2024-01-01 08:28:34 +00:00
|
|
|
let _ = <i64 as TryFrom<i32>>::try_from(0).unwrap();
|
2024-01-01 17:23:44 +00:00
|
|
|
//~^ ERROR: use of a fallible conversion when an infallible one could be used
|
|
|
|
|
2024-01-01 08:28:34 +00:00
|
|
|
let _ = <i64 as TryFrom<i32>>::try_from(0).expect("can't happen");
|
2024-01-01 17:23:44 +00:00
|
|
|
//~^ ERROR: use of a fallible conversion when an infallible one could be used
|
|
|
|
|
|
|
|
// --- TryIntoFunction `<U as TryInto<_>>::try_into(U)` ---
|
2024-01-01 08:17:46 +00:00
|
|
|
|
|
|
|
let _: i64 = <i32 as TryInto<_>>::try_into(0).unwrap();
|
2024-01-01 17:23:44 +00:00
|
|
|
//~^ ERROR: use of a fallible conversion when an infallible one could be used
|
|
|
|
|
2024-01-01 08:17:46 +00:00
|
|
|
let _: i64 = <i32 as TryInto<_>>::try_into(0).expect("can't happen");
|
2024-01-01 17:23:44 +00:00
|
|
|
//~^ ERROR: use of a fallible conversion when an infallible one could be used
|
2023-10-14 22:57:33 +00:00
|
|
|
}
|