fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1#![allow(dead_code)] 2#![warn(clippy::cast_lossless)] 3 4fn main() { 5 // Test clippy::cast_lossless with casts to integer types 6 let _ = u8::from(true); 7 let _ = u16::from(true); 8 let _ = u32::from(true); 9 let _ = u64::from(true); 10 let _ = u128::from(true); 11 let _ = usize::from(true); 12 13 let _ = i8::from(true); 14 let _ = i16::from(true); 15 let _ = i32::from(true); 16 let _ = i64::from(true); 17 let _ = i128::from(true); 18 let _ = isize::from(true); 19 20 // Test with an expression wrapped in parens 21 let _ = u16::from(true | false); 22} 23 24// The lint would suggest using `u32::from(input)` here but the `XX::from` function is not const, 25// so we skip the lint if the expression is in a const fn. 26// See #3656 27const fn abc(input: bool) -> u32 { 28 input as u32 29} 30 31// Same as the above issue. We can't suggest `::from` in const fns in impls 32mod cast_lossless_in_impl { 33 struct A; 34 35 impl A { 36 pub const fn convert(x: bool) -> u64 { 37 x as u64 38 } 39 } 40} 41 42#[clippy::msrv = "1.27"] 43fn msrv_1_27() { 44 let _ = true as u8; 45} 46 47#[clippy::msrv = "1.28"] 48fn msrv_1_28() { 49 let _ = u8::from(true); 50}