about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorTennyZhuang <zty0826@gmail.com>2022-10-02 17:12:08 +0800
committerTennyZhuang <zty0826@gmail.com>2022-10-02 23:02:11 +0800
commit081f73954b24e87bbbd95ed20f9a504680b21d46 (patch)
treea8cf7ca73ce92e1b88a583f45d7f3771e3afe4da /tests
parentac12011315e0447cf7294102a342793c1d8c7cb8 (diff)
downloadrust-081f73954b24e87bbbd95ed20f9a504680b21d46.tar.gz
rust-081f73954b24e87bbbd95ed20f9a504680b21d46.zip
let unnecessary_cast work for trivial non_literal expressions
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/unnecessary_cast.fixed8
-rw-r--r--tests/ui/unnecessary_cast.rs8
-rw-r--r--tests/ui/unnecessary_cast.stderr8
3 files changed, 23 insertions, 1 deletions
diff --git a/tests/ui/unnecessary_cast.fixed b/tests/ui/unnecessary_cast.fixed
index 70ec3e94380..94dc9642726 100644
--- a/tests/ui/unnecessary_cast.fixed
+++ b/tests/ui/unnecessary_cast.fixed
@@ -103,4 +103,12 @@ mod fixable {
         #[allow(clippy::precedence)]
         let _: f64 = -8.0_f64.exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior
     }
+
+    fn issue_9562_non_literal() {
+        fn foo() -> f32 {
+            0.
+        }
+
+        let _num = foo();
+    }
 }
diff --git a/tests/ui/unnecessary_cast.rs b/tests/ui/unnecessary_cast.rs
index 36c1a87fab6..e5150256f69 100644
--- a/tests/ui/unnecessary_cast.rs
+++ b/tests/ui/unnecessary_cast.rs
@@ -103,4 +103,12 @@ mod fixable {
         #[allow(clippy::precedence)]
         let _: f64 = -(8.0 as f64).exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior
     }
+
+    fn issue_9562_non_literal() {
+        fn foo() -> f32 {
+            0.
+        }
+
+        let _num = foo() as f32;
+    }
 }
diff --git a/tests/ui/unnecessary_cast.stderr b/tests/ui/unnecessary_cast.stderr
index a52b92c339c..e5c3dd5e53f 100644
--- a/tests/ui/unnecessary_cast.stderr
+++ b/tests/ui/unnecessary_cast.stderr
@@ -174,5 +174,11 @@ error: casting float literal to `f64` is unnecessary
 LL |         let _: f64 = -(8.0 as f64).exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior
    |                       ^^^^^^^^^^^^ help: try: `8.0_f64`
 
-error: aborting due to 29 previous errors
+error: casting to the same type is unnecessary (`f32` -> `f32`)
+  --> $DIR/unnecessary_cast.rs:112:20
+   |
+LL |         let _num = foo() as f32;
+   |                    ^^^^^^^^^^^^ help: try: `foo()`
+
+error: aborting due to 30 previous errors