about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkoka <koka.code@gmail.com>2022-11-18 21:23:16 +0900
committerkoka <koka.code@gmail.com>2022-11-18 21:23:16 +0900
commit921f4d317ec3498b0583a72ba1dfdfd84699c268 (patch)
tree2e56691a8d8c1514199e5a957a8cc47fdfadec02
parentdfe37f13cfb935f4dff56785ce63131b0d6c85c4 (diff)
downloadrust-921f4d317ec3498b0583a72ba1dfdfd84699c268.tar.gz
rust-921f4d317ec3498b0583a72ba1dfdfd84699c268.zip
Keep original literal notation in suggestion
-rw-r--r--clippy_lints/src/unused_rounding.rs2
-rw-r--r--tests/ui/unused_rounding.fixed5
-rw-r--r--tests/ui/unused_rounding.rs5
-rw-r--r--tests/ui/unused_rounding.stderr8
4 files changed, 18 insertions, 2 deletions
diff --git a/clippy_lints/src/unused_rounding.rs b/clippy_lints/src/unused_rounding.rs
index 3164937293b..0f6f36da820 100644
--- a/clippy_lints/src/unused_rounding.rs
+++ b/clippy_lints/src/unused_rounding.rs
@@ -36,7 +36,7 @@ fn is_useless_rounding(expr: &Expr) -> Option<(&str, String)> {
         && let ExprKind::Lit(spanned) = &receiver.kind
         && let LitKind::Float(symbol, ty) = spanned.kind {
             let f = symbol.as_str().parse::<f64>().unwrap();
-            let f_str = symbol.to_string() + if let LitFloatType::Suffixed(ty) = ty {
+            let f_str = spanned.token_lit.symbol.to_string() + if let LitFloatType::Suffixed(ty) = ty {
                 ty.name_str()
             } else {
                 ""
diff --git a/tests/ui/unused_rounding.fixed b/tests/ui/unused_rounding.fixed
index 54f85806ac3..38fe6c34cfe 100644
--- a/tests/ui/unused_rounding.fixed
+++ b/tests/ui/unused_rounding.fixed
@@ -6,4 +6,9 @@ fn main() {
     let _ = 1.0f64;
     let _ = 1.00f32;
     let _ = 2e-54f64.floor();
+
+    // issue9866
+    let _ = 3.3_f32.round();
+    let _ = 3.3_f64.round();
+    let _ = 3.0_f32;
 }
diff --git a/tests/ui/unused_rounding.rs b/tests/ui/unused_rounding.rs
index 8d007bc4a1d..a5cac64d023 100644
--- a/tests/ui/unused_rounding.rs
+++ b/tests/ui/unused_rounding.rs
@@ -6,4 +6,9 @@ fn main() {
     let _ = 1.0f64.floor();
     let _ = 1.00f32.round();
     let _ = 2e-54f64.floor();
+
+    // issue9866
+    let _ = 3.3_f32.round();
+    let _ = 3.3_f64.round();
+    let _ = 3.0_f32.round();
 }
diff --git a/tests/ui/unused_rounding.stderr b/tests/ui/unused_rounding.stderr
index 6cfb02e0402..1eeb5d1de88 100644
--- a/tests/ui/unused_rounding.stderr
+++ b/tests/ui/unused_rounding.stderr
@@ -18,5 +18,11 @@ error: used the `round` method with a whole number float
 LL |     let _ = 1.00f32.round();
    |             ^^^^^^^^^^^^^^^ help: remove the `round` method call: `1.00f32`
 
-error: aborting due to 3 previous errors
+error: used the `round` method with a whole number float
+  --> $DIR/unused_rounding.rs:13:13
+   |
+LL |     let _ = 3.0_f32.round();
+   |             ^^^^^^^^^^^^^^^ help: remove the `round` method call: `3.0_f32`
+
+error: aborting due to 4 previous errors