]> git.lizzy.rs Git - rust.git/blob - tests/ui/cast_lossless_float.fixed
Move MSRV tests into the lint specific test files
[rust.git] / tests / ui / cast_lossless_float.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 floating-point types
8     let x0 = 1i8;
9     let _ = f32::from(x0);
10     let _ = f64::from(x0);
11     let x1 = 1u8;
12     let _ = f32::from(x1);
13     let _ = f64::from(x1);
14     let x2 = 1i16;
15     let _ = f32::from(x2);
16     let _ = f64::from(x2);
17     let x3 = 1u16;
18     let _ = f32::from(x3);
19     let _ = f64::from(x3);
20     let x4 = 1i32;
21     let _ = f64::from(x4);
22     let x5 = 1u32;
23     let _ = f64::from(x5);
24
25     // Test with casts from floating-point types
26     let _ = f64::from(1.0f32);
27 }
28
29 // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const,
30 // so we skip the lint if the expression is in a const fn.
31 // See #3656
32 const fn abc(input: f32) -> f64 {
33     input as f64
34 }
35
36 // Same as the above issue. We can't suggest `::from` in const fns in impls
37 mod cast_lossless_in_impl {
38     struct A;
39
40     impl A {
41         pub const fn convert(x: f32) -> f64 {
42             x as f64
43         }
44     }
45 }