Skip to content

Commit bfa2691

Browse files
committed
Run cargo dev fmt
1 parent 028cddb commit bfa2691

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

clippy_lints/src/floating_point_arithmetic.rs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,28 @@ fn is_zero(expr: &Expr<'_>) -> bool {
422422

423423
fn check_custom_abs(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
424424
if let Some((cond, body, Some(else_body))) = higher::if_block(&expr) {
425-
if let ExprKind::Block( Block { stmts: [], expr: Some(Expr { kind: ExprKind::Unary(UnOp::UnNeg, else_expr), .. }), .. }, _,) = else_body.kind {
426-
if let ExprKind::Block( Block { stmts: [], expr: Some(body), .. }, _,) = &body.kind {
425+
if let ExprKind::Block(
426+
Block {
427+
stmts: [],
428+
expr:
429+
Some(Expr {
430+
kind: ExprKind::Unary(UnOp::UnNeg, else_expr),
431+
..
432+
}),
433+
..
434+
},
435+
_,
436+
) = else_body.kind
437+
{
438+
if let ExprKind::Block(
439+
Block {
440+
stmts: [],
441+
expr: Some(body),
442+
..
443+
},
444+
_,
445+
) = &body.kind
446+
{
427447
if are_exprs_equal(cx, else_expr, body) {
428448
if is_testing_positive(cx, cond, body) {
429449
span_lint_and_sugg(
@@ -449,9 +469,28 @@ fn check_custom_abs(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
449469
}
450470
}
451471
}
452-
if let ExprKind::Block( Block { stmts: [], expr: Some(Expr { kind: ExprKind::Unary(UnOp::UnNeg, else_expr), .. }), .. }, _,) = &body.kind
472+
if let ExprKind::Block(
473+
Block {
474+
stmts: [],
475+
expr:
476+
Some(Expr {
477+
kind: ExprKind::Unary(UnOp::UnNeg, else_expr),
478+
..
479+
}),
480+
..
481+
},
482+
_,
483+
) = &body.kind
453484
{
454-
if let ExprKind::Block( Block { stmts: [], expr: Some(body), .. }, _,) = &else_body.kind {
485+
if let ExprKind::Block(
486+
Block {
487+
stmts: [],
488+
expr: Some(body),
489+
..
490+
},
491+
_,
492+
) = &else_body.kind
493+
{
455494
if are_exprs_equal(cx, else_expr, body) {
456495
if is_testing_negative(cx, cond, body) {
457496
span_lint_and_sugg(

tests/ui/floating_point_abs.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
struct A {
44
a: f64,
5-
b: f64
5+
b: f64,
66
}
77

88
fn fake_abs1(num: f64) -> f64 {
@@ -62,11 +62,10 @@ fn fake_nabs2(num: f64) -> f64 {
6262
}
6363

6464
fn fake_nabs3(a: A) -> A {
65-
A { a: if a.a >= 0.0 {
66-
-a.a
67-
} else {
68-
a.a
69-
}, b: a.b }
65+
A {
66+
a: if a.a >= 0.0 { -a.a } else { a.a },
67+
b: a.b,
68+
}
7069
}
7170

7271
fn not_fake_abs1(num: f64) -> f64 {

0 commit comments

Comments
 (0)