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