]> git.lizzy.rs Git - rust.git/blob - tests/ui/cast_lossless_integer.fixed
Prevent incorrect cast_lossless suggestion in const_fn
[rust.git] / 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     i16::from(1i8);
9     i32::from(1i8);
10     i64::from(1i8);
11     i16::from(1u8);
12     i32::from(1u8);
13     i64::from(1u8);
14     u16::from(1u8);
15     u32::from(1u8);
16     u64::from(1u8);
17     i32::from(1i16);
18     i64::from(1i16);
19     i32::from(1u16);
20     i64::from(1u16);
21     u32::from(1u16);
22     u64::from(1u16);
23     i64::from(1i32);
24     i64::from(1u32);
25     u64::from(1u32);
26 }
27
28 // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const,
29 // so we skip the lint if the expression is in a const fn.
30 // See #3656
31 const fn abc(input: u16) -> u32 {
32     input as u32
33 }