fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
1.1 KiB43 linesraw
1#![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)]
2#![warn(clippy::cast_lossless)]
3
4fn main() {
5    // Test clippy::cast_lossless with casts to floating-point types
6    let x0 = 1i8;
7    let _ = f32::from(x0);
8    let _ = f64::from(x0);
9    let x1 = 1u8;
10    let _ = f32::from(x1);
11    let _ = f64::from(x1);
12    let x2 = 1i16;
13    let _ = f32::from(x2);
14    let _ = f64::from(x2);
15    let x3 = 1u16;
16    let _ = f32::from(x3);
17    let _ = f64::from(x3);
18    let x4 = 1i32;
19    let _ = f64::from(x4);
20    let x5 = 1u32;
21    let _ = f64::from(x5);
22
23    // Test with casts from floating-point types
24    let _ = f64::from(1.0f32);
25}
26
27// The lint would suggest using `f64::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
30const fn abc(input: f32) -> f64 {
31    input as f64
32}
33
34// Same as the above issue. We can't suggest `::from` in const fns in impls
35mod cast_lossless_in_impl {
36    struct A;
37
38    impl A {
39        pub const fn convert(x: f32) -> f64 {
40            x as f64
41        }
42    }
43}