]> git.lizzy.rs Git - rust.git/commitdiff
Use `utils::sugg` in `FLOAT_CMP`
authormcarton <cartonmartin+git@gmail.com>
Wed, 29 Jun 2016 19:25:23 +0000 (21:25 +0200)
committermcarton <cartonmartin+git@gmail.com>
Fri, 1 Jul 2016 15:12:48 +0000 (17:12 +0200)
clippy_lints/src/misc.rs
tests/compile-fail/float_cmp.rs

index e57cd50899efb7fb6fb189f400c1d8355543ff39..9c04ad6f3e4522ba962ec0680a2520fd99d94a3e 100644 (file)
@@ -13,6 +13,7 @@
     get_item_name, get_parent_expr, implements_trait, in_macro, is_integer_literal, match_path,
     snippet, span_lint, span_lint_and_then, walk_ptrs_ty
 };
+use utils::sugg::Sugg;
 
 /// **What it does:** This lint checks for function arguments and let bindings denoted as `ref`.
 ///
@@ -169,11 +170,12 @@ fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
                                    expr.span,
                                    "strict comparison of f32 or f64",
                                    |db| {
+                    let lhs = &Sugg::hir(cx, left, "..");
+                    let rhs = &Sugg::hir(cx, right, "..");
+
                     db.span_suggestion(expr.span,
                                        "consider comparing them within some error",
-                                       format!("({} - {}).abs() < error",
-                                               snippet(cx, left.span, ".."),
-                                               snippet(cx, right.span, "..")));
+                                       format!("({}).abs() < error", lhs - rhs));
                     db.span_note(expr.span, "std::f32::EPSILON and std::f64::EPSILON are available.");
                 });
             }
index cf8cefb3af3e0be41be6a32d1fcd44167d0f8688..314cc721425507dd3ebf3d01c578f93073c51d5c 100644 (file)
@@ -44,12 +44,12 @@ fn main() {
     //~^ ERROR strict comparison of f32 or f64
     //~| HELP within some error
     //~| SUGGESTION (ONE - 1f32).abs() < error
-    ONE == (1.0 + 0.0);
+    ONE == 1.0 + 0.0;
     //~^ ERROR strict comparison of f32 or f64
     //~| HELP within some error
     //~| SUGGESTION (ONE - (1.0 + 0.0)).abs() < error
 
-    ONE + ONE == (ZERO + ONE + ONE);
+    ONE + ONE == ZERO + ONE + ONE;
     //~^ ERROR strict comparison of f32 or f64
     //~| HELP within some error
     //~| SUGGESTION (ONE + ONE - (ZERO + ONE + ONE)).abs() < error