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