]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/cast_lossless_integer.fixed
Merge commit '4bdfb0741dbcecd5279a2635c3280726db0604b5' into clippyup
[rust.git] / src / tools / clippy / tests / ui / cast_lossless_integer.fixed
1 // run-rustfix
2
3 #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)]
4 #![warn(clippy::cast_lossless)]
5
6 fn main() {
7     // Test clippy::cast_lossless with casts to integer types
8     let _ = i16::from(1i8);
9     let _ = i32::from(1i8);
10     let _ = i64::from(1i8);
11     let _ = i16::from(1u8);
12     let _ = i32::from(1u8);
13     let _ = i64::from(1u8);
14     let _ = u16::from(1u8);
15     let _ = u32::from(1u8);
16     let _ = u64::from(1u8);
17     let _ = i32::from(1i16);
18     let _ = i64::from(1i16);
19     let _ = i32::from(1u16);
20     let _ = i64::from(1u16);
21     let _ = u32::from(1u16);
22     let _ = u64::from(1u16);
23     let _ = i64::from(1i32);
24     let _ = i64::from(1u32);
25     let _ = u64::from(1u32);
26
27     // Test with an expression wrapped in parens
28     let _ = u16::from(1u8 + 1u8);
29 }
30
31 // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const,
32 // so we skip the lint if the expression is in a const fn.
33 // See #3656
34 const fn abc(input: u16) -> u32 {
35     input as u32
36 }
37
38 // Same as the above issue. We can't suggest `::from` in const fns in impls
39 mod cast_lossless_in_impl {
40     struct A;
41
42     impl A {
43         pub const fn convert(x: u32) -> u64 {
44             x as u64
45         }
46     }
47 }
48
49 #[derive(PartialEq, Debug)]
50 #[repr(i64)]
51 enum Test {
52     A = u32::MAX as i64 + 1,
53 }