about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJarredAllen <jarredallen73@gmail.com>2020-02-29 18:51:39 -0800
committerJarredAllen <jarredallen73@gmail.com>2020-02-29 18:51:39 -0800
commitbfa2691559bf9dd26dc90aa564305aef1f164aec (patch)
treea87b3f7d0c4705610e936a7eb5d99816b7ab547f
parent028cddb95628252180bf6146b445e146dcdef8b2 (diff)
downloadrust-bfa2691559bf9dd26dc90aa564305aef1f164aec.tar.gz
rust-bfa2691559bf9dd26dc90aa564305aef1f164aec.zip
Run cargo dev fmt
-rw-r--r--clippy_lints/src/floating_point_arithmetic.rs47
-rw-r--r--tests/ui/floating_point_abs.rs11
2 files changed, 48 insertions, 10 deletions
diff --git a/clippy_lints/src/floating_point_arithmetic.rs b/clippy_lints/src/floating_point_arithmetic.rs
index 8a6ae10ab0b..443ccf17896 100644
--- a/clippy_lints/src/floating_point_arithmetic.rs
+++ b/clippy_lints/src/floating_point_arithmetic.rs
@@ -422,8 +422,28 @@ fn is_zero(expr: &Expr<'_>) -> bool {
 
 fn check_custom_abs(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
     if let Some((cond, body, Some(else_body))) = higher::if_block(&expr) {
-        if let ExprKind::Block( Block { stmts: [], expr: Some(Expr { kind: ExprKind::Unary(UnOp::UnNeg, else_expr), ..  }), ..  }, _,) = else_body.kind {
-            if let ExprKind::Block( Block { stmts: [], expr: Some(body), ..  }, _,) = &body.kind {
+        if let ExprKind::Block(
+            Block {
+                stmts: [],
+                expr:
+                    Some(Expr {
+                        kind: ExprKind::Unary(UnOp::UnNeg, else_expr),
+                        ..
+                    }),
+                ..
+            },
+            _,
+        ) = else_body.kind
+        {
+            if let ExprKind::Block(
+                Block {
+                    stmts: [],
+                    expr: Some(body),
+                    ..
+                },
+                _,
+            ) = &body.kind
+            {
                 if are_exprs_equal(cx, else_expr, body) {
                     if is_testing_positive(cx, cond, body) {
                         span_lint_and_sugg(
@@ -449,9 +469,28 @@ fn check_custom_abs(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
                 }
             }
         }
-        if let ExprKind::Block( Block { stmts: [], expr: Some(Expr { kind: ExprKind::Unary(UnOp::UnNeg, else_expr), ..  }), ..  }, _,) = &body.kind
+        if let ExprKind::Block(
+            Block {
+                stmts: [],
+                expr:
+                    Some(Expr {
+                        kind: ExprKind::Unary(UnOp::UnNeg, else_expr),
+                        ..
+                    }),
+                ..
+            },
+            _,
+        ) = &body.kind
         {
-            if let ExprKind::Block( Block { stmts: [], expr: Some(body), ..  }, _,) = &else_body.kind {
+            if let ExprKind::Block(
+                Block {
+                    stmts: [],
+                    expr: Some(body),
+                    ..
+                },
+                _,
+            ) = &else_body.kind
+            {
                 if are_exprs_equal(cx, else_expr, body) {
                     if is_testing_negative(cx, cond, body) {
                         span_lint_and_sugg(
diff --git a/tests/ui/floating_point_abs.rs b/tests/ui/floating_point_abs.rs
index 40d2ff7e859..b0c15e57e40 100644
--- a/tests/ui/floating_point_abs.rs
+++ b/tests/ui/floating_point_abs.rs
@@ -2,7 +2,7 @@
 
 struct A {
     a: f64,
-    b: f64
+    b: f64,
 }
 
 fn fake_abs1(num: f64) -> f64 {
@@ -62,11 +62,10 @@ fn fake_nabs2(num: f64) -> f64 {
 }
 
 fn fake_nabs3(a: A) -> A {
-    A { a: if a.a >= 0.0 {
-            -a.a
-        } else {
-            a.a
-        }, b: a.b }
+    A {
+        a: if a.a >= 0.0 { -a.a } else { a.a },
+        b: a.b,
+    }
 }
 
 fn not_fake_abs1(num: f64) -> f64 {