From bfa2691559bf9dd26dc90aa564305aef1f164aec Mon Sep 17 00:00:00 2001 From: JarredAllen Date: Sat, 29 Feb 2020 18:51:39 -0800 Subject: [PATCH] Run cargo dev fmt --- clippy_lints/src/floating_point_arithmetic.rs | 47 +++++++++++++++++-- tests/ui/floating_point_abs.rs | 11 ++--- 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 {