]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/cast_lossless_float.rs
iterate List by value
[rust.git] / tests / ui / cast_lossless_float.rs
index a8d5ed2508c7f4793ff68b9a584191647070cba6..eb0aab8864290978ee6505e616f3a7050d731a1c 100644 (file)
@@ -21,6 +21,9 @@ fn main() {
     x4 as f64;
     let x5 = 1u32;
     x5 as f64;
+
+    // Test with casts from floating-point types
+    1.0f32 as f64;
 }
 
 // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const,
@@ -29,3 +32,14 @@ fn main() {
 const fn abc(input: f32) -> f64 {
     input as f64
 }
+
+// Same as the above issue. We can't suggest `::from` in const fns in impls
+mod cast_lossless_in_impl {
+    struct A;
+
+    impl A {
+        pub const fn convert(x: f32) -> f64 {
+            x as f64
+        }
+    }
+}