about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/operators/identity_op.rs9
-rw-r--r--tests/ui/identity_op.fixed3
-rw-r--r--tests/ui/identity_op.rs3
-rw-r--r--tests/ui/identity_op.stderr18
4 files changed, 20 insertions, 13 deletions
diff --git a/clippy_lints/src/operators/identity_op.rs b/clippy_lints/src/operators/identity_op.rs
index e3ce1ae9427..76993785727 100644
--- a/clippy_lints/src/operators/identity_op.rs
+++ b/clippy_lints/src/operators/identity_op.rs
@@ -67,13 +67,8 @@ pub(crate) fn check<'tcx>(
         },
         BinOpKind::Div => {
             if is_redundant_op(cx, right, 1) {
-                span_ineffective_operation(
-                    cx,
-                    expr.span,
-                    peeled_left_span,
-                    Parens::Unneeded,
-                    left_is_coerced_to_value,
-                );
+                let paren = needs_parenthesis(cx, expr, left);
+                span_ineffective_operation(cx, expr.span, peeled_left_span, paren, left_is_coerced_to_value);
             }
         },
         BinOpKind::BitAnd => {
diff --git a/tests/ui/identity_op.fixed b/tests/ui/identity_op.fixed
index 927142d5f80..b80ba701c3a 100644
--- a/tests/ui/identity_op.fixed
+++ b/tests/ui/identity_op.fixed
@@ -232,6 +232,9 @@ fn issue_13470() {
     // If we don't maintain the parens here, the behavior changes
     let _ = -(x + y);
     //~^ ERROR: this operation has no effect
+    // Similarly, we need to maintain parens here
+    let _ = -(x / y);
+    //~^ ERROR: this operation has no effect
     // Maintain parenthesis if the parent expr is of higher precedence
     let _ = 2i32 * (x + y);
     //~^ ERROR: this operation has no effect
diff --git a/tests/ui/identity_op.rs b/tests/ui/identity_op.rs
index a50546929a8..3e20fa6f2b8 100644
--- a/tests/ui/identity_op.rs
+++ b/tests/ui/identity_op.rs
@@ -232,6 +232,9 @@ fn issue_13470() {
     // If we don't maintain the parens here, the behavior changes
     let _ = -(x + y + 0i32);
     //~^ ERROR: this operation has no effect
+    // Similarly, we need to maintain parens here
+    let _ = -(x / y / 1i32);
+    //~^ ERROR: this operation has no effect
     // Maintain parenthesis if the parent expr is of higher precedence
     let _ = 2i32 * (x + y + 0i32);
     //~^ ERROR: this operation has no effect
diff --git a/tests/ui/identity_op.stderr b/tests/ui/identity_op.stderr
index 79d1a7bd81c..3f5cab5404d 100644
--- a/tests/ui/identity_op.stderr
+++ b/tests/ui/identity_op.stderr
@@ -344,34 +344,40 @@ LL |     let _ = -(x + y + 0i32);
    |              ^^^^^^^^^^^^^^ help: consider reducing it to: `(x + y)`
 
 error: this operation has no effect
-  --> tests/ui/identity_op.rs:236:20
+  --> tests/ui/identity_op.rs:236:14
+   |
+LL |     let _ = -(x / y / 1i32);
+   |              ^^^^^^^^^^^^^^ help: consider reducing it to: `(x / y)`
+
+error: this operation has no effect
+  --> tests/ui/identity_op.rs:239:20
    |
 LL |     let _ = 2i32 * (x + y + 0i32);
    |                    ^^^^^^^^^^^^^^ help: consider reducing it to: `(x + y)`
 
 error: this operation has no effect
-  --> tests/ui/identity_op.rs:240:20
+  --> tests/ui/identity_op.rs:243:20
    |
 LL |     let _ = 2i32 - (x - y - 0i32);
    |                    ^^^^^^^^^^^^^^ help: consider reducing it to: `(x - y)`
 
 error: this operation has no effect
-  --> tests/ui/identity_op.rs:244:17
+  --> tests/ui/identity_op.rs:247:17
    |
 LL |     let _ = 2 + (x + (y * z) + 0);
    |                 ^^^^^^^^^^^^^^^^^ help: consider reducing it to: `x + (y * z)`
 
 error: this operation has no effect
-  --> tests/ui/identity_op.rs:248:20
+  --> tests/ui/identity_op.rs:251:20
    |
 LL |     let _ = 2i32 + (x * y * 1i32);
    |                    ^^^^^^^^^^^^^^ help: consider reducing it to: `(x * y)`
 
 error: this operation has no effect
-  --> tests/ui/identity_op.rs:253:25
+  --> tests/ui/identity_op.rs:256:25
    |
 LL |     let _: u64 = 1u64 + ((x as i32 + y as i32) as u64 + 0u64);
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(x as i32 + y as i32) as u64`
 
-error: aborting due to 62 previous errors
+error: aborting due to 63 previous errors