From 49adc99aed258c36d2dd072327c7256ea9c7b476 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 20 Sep 2019 14:54:16 +0900 Subject: [PATCH] op_ref: Move tests out of eq_op file --- tests/ui/eq_op.rs | 37 +------------------- tests/ui/eq_op.stderr | 78 ++++++++++++++++++------------------------ tests/ui/op_ref.rs | 39 ++++++++++++++++++++- tests/ui/op_ref.stderr | 14 ++++++-- 4 files changed, 84 insertions(+), 84 deletions(-) diff --git a/tests/ui/eq_op.rs b/tests/ui/eq_op.rs index cc0935ddb79..2d2689075a1 100644 --- a/tests/ui/eq_op.rs +++ b/tests/ui/eq_op.rs @@ -3,6 +3,7 @@ #[allow(clippy::identity_op, clippy::double_parens, clippy::many_single_char_names)] #[allow(clippy::no_effect, unused_variables, clippy::unnecessary_operation, clippy::short_circuit_statement)] #[warn(clippy::nonminimal_bool)] +#[allow(unused)] fn main() { // simple values and comparisons 1 == 1; @@ -50,42 +51,6 @@ fn main() { 2*a.len() == 2*a.len(); // ok, functions a.pop() == a.pop(); // ok, functions - use std::ops::BitAnd; - struct X(i32); - impl BitAnd for X { - type Output = X; - fn bitand(self, rhs: X) -> X { - X(self.0 & rhs.0) - } - } - impl<'a> BitAnd<&'a X> for X { - type Output = X; - fn bitand(self, rhs: &'a X) -> X { - X(self.0 & rhs.0) - } - } - let x = X(1); - let y = X(2); - let z = x & &y; - - #[derive(Copy, Clone)] - struct Y(i32); - impl BitAnd for Y { - type Output = Y; - fn bitand(self, rhs: Y) -> Y { - Y(self.0 & rhs.0) - } - } - impl<'a> BitAnd<&'a Y> for Y { - type Output = Y; - fn bitand(self, rhs: &'a Y) -> Y { - Y(self.0 & rhs.0) - } - } - let x = Y(1); - let y = Y(2); - let z = x & &y; - check_ignore_macro(); // named constants diff --git a/tests/ui/eq_op.stderr b/tests/ui/eq_op.stderr index 2dabaf0d4db..2a2f95c677c 100644 --- a/tests/ui/eq_op.stderr +++ b/tests/ui/eq_op.stderr @@ -1,5 +1,5 @@ error: this boolean expression can be simplified - --> $DIR/eq_op.rs:35:5 + --> $DIR/eq_op.rs:36:5 | LL | true && true; | ^^^^^^^^^^^^ help: try: `true` @@ -7,37 +7,37 @@ LL | true && true; = note: `-D clippy::nonminimal-bool` implied by `-D warnings` error: this boolean expression can be simplified - --> $DIR/eq_op.rs:37:5 + --> $DIR/eq_op.rs:38:5 | LL | true || true; | ^^^^^^^^^^^^ help: try: `true` error: this boolean expression can be simplified - --> $DIR/eq_op.rs:43:5 + --> $DIR/eq_op.rs:44:5 | LL | a == b && b == a; | ^^^^^^^^^^^^^^^^ help: try: `a == b` error: this boolean expression can be simplified - --> $DIR/eq_op.rs:44:5 + --> $DIR/eq_op.rs:45:5 | LL | a != b && b != a; | ^^^^^^^^^^^^^^^^ help: try: `a != b` error: this boolean expression can be simplified - --> $DIR/eq_op.rs:45:5 + --> $DIR/eq_op.rs:46:5 | LL | a < b && b > a; | ^^^^^^^^^^^^^^ help: try: `a < b` error: this boolean expression can be simplified - --> $DIR/eq_op.rs:46:5 + --> $DIR/eq_op.rs:47:5 | LL | a <= b && b >= a; | ^^^^^^^^^^^^^^^^ help: try: `a <= b` error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:8:5 + --> $DIR/eq_op.rs:9:5 | LL | 1 == 1; | ^^^^^^ @@ -45,170 +45,160 @@ LL | 1 == 1; = note: `-D clippy::eq-op` implied by `-D warnings` error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:9:5 + --> $DIR/eq_op.rs:10:5 | LL | "no" == "no"; | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:11:5 + --> $DIR/eq_op.rs:12:5 | LL | false != false; | ^^^^^^^^^^^^^^ error: equal expressions as operands to `<` - --> $DIR/eq_op.rs:12:5 + --> $DIR/eq_op.rs:13:5 | LL | 1.5 < 1.5; | ^^^^^^^^^ error: equal expressions as operands to `>=` - --> $DIR/eq_op.rs:13:5 + --> $DIR/eq_op.rs:14:5 | LL | 1u64 >= 1u64; | ^^^^^^^^^^^^ error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:16:5 + --> $DIR/eq_op.rs:17:5 | LL | (1 as u64) & (1 as u64); | ^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `^` - --> $DIR/eq_op.rs:17:5 + --> $DIR/eq_op.rs:18:5 | LL | 1 ^ ((((((1)))))); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `<` - --> $DIR/eq_op.rs:20:5 + --> $DIR/eq_op.rs:21:5 | LL | (-(2) < -(2)); | ^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:21:5 + --> $DIR/eq_op.rs:22:5 | LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:21:6 + --> $DIR/eq_op.rs:22:6 | LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:21:27 + --> $DIR/eq_op.rs:22:27 | LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:22:5 + --> $DIR/eq_op.rs:23:5 | LL | (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:25:5 + --> $DIR/eq_op.rs:26:5 | LL | ([1] != [1]); | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:26:5 + --> $DIR/eq_op.rs:27:5 | LL | ((1, 2) != (1, 2)); | ^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:30:5 + --> $DIR/eq_op.rs:31:5 | LL | 1 + 1 == 2; | ^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:31:5 + --> $DIR/eq_op.rs:32:5 | LL | 1 - 1 == 0; | ^^^^^^^^^^ error: equal expressions as operands to `-` - --> $DIR/eq_op.rs:31:5 + --> $DIR/eq_op.rs:32:5 | LL | 1 - 1 == 0; | ^^^^^ error: equal expressions as operands to `-` - --> $DIR/eq_op.rs:33:5 + --> $DIR/eq_op.rs:34:5 | LL | 1 - 1; | ^^^^^ error: equal expressions as operands to `/` - --> $DIR/eq_op.rs:34:5 + --> $DIR/eq_op.rs:35:5 | LL | 1 / 1; | ^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:35:5 + --> $DIR/eq_op.rs:36:5 | LL | true && true; | ^^^^^^^^^^^^ error: equal expressions as operands to `||` - --> $DIR/eq_op.rs:37:5 + --> $DIR/eq_op.rs:38:5 | LL | true || true; | ^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:43:5 + --> $DIR/eq_op.rs:44:5 | LL | a == b && b == a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:44:5 + --> $DIR/eq_op.rs:45:5 | LL | a != b && b != a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:45:5 + --> $DIR/eq_op.rs:46:5 | LL | a < b && b > a; | ^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:46:5 + --> $DIR/eq_op.rs:47:5 | LL | a <= b && b >= a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:49:5 + --> $DIR/eq_op.rs:50:5 | LL | a == a; | ^^^^^^ -error: taken reference of right operand - --> $DIR/eq_op.rs:87:13 - | -LL | let z = x & &y; - | ^^^^-- - | | - | help: use the right value directly: `y` - | - = note: `-D clippy::op-ref` implied by `-D warnings` - error: equal expressions as operands to `/` - --> $DIR/eq_op.rs:95:20 + --> $DIR/eq_op.rs:60:20 | LL | const D: u32 = A / A; | ^^^^^ -error: aborting due to 34 previous errors +error: aborting due to 33 previous errors diff --git a/tests/ui/op_ref.rs b/tests/ui/op_ref.rs index bf43deca12c..6605c967c8e 100644 --- a/tests/ui/op_ref.rs +++ b/tests/ui/op_ref.rs @@ -1,6 +1,8 @@ #![allow(unused_variables, clippy::blacklisted_name)] - +#![warn(clippy::op_ref)] +#![allow(clippy::many_single_char_names)] use std::collections::HashSet; +use std::ops::BitAnd; fn main() { let tracked_fds: HashSet = HashSet::new(); @@ -18,4 +20,39 @@ fn main() { if b < &a { println!("OK"); } + + struct X(i32); + impl BitAnd for X { + type Output = X; + fn bitand(self, rhs: X) -> X { + X(self.0 & rhs.0) + } + } + impl<'a> BitAnd<&'a X> for X { + type Output = X; + fn bitand(self, rhs: &'a X) -> X { + X(self.0 & rhs.0) + } + } + let x = X(1); + let y = X(2); + let z = x & &y; + + #[derive(Copy, Clone)] + struct Y(i32); + impl BitAnd for Y { + type Output = Y; + fn bitand(self, rhs: Y) -> Y { + Y(self.0 & rhs.0) + } + } + impl<'a> BitAnd<&'a Y> for Y { + type Output = Y; + fn bitand(self, rhs: &'a Y) -> Y { + Y(self.0 & rhs.0) + } + } + let x = Y(1); + let y = Y(2); + let z = x & &y; } diff --git a/tests/ui/op_ref.stderr b/tests/ui/op_ref.stderr index f5c5b970261..0f6a45f905c 100644 --- a/tests/ui/op_ref.stderr +++ b/tests/ui/op_ref.stderr @@ -1,5 +1,5 @@ error: needlessly taken reference of both operands - --> $DIR/op_ref.rs:10:15 + --> $DIR/op_ref.rs:12:15 | LL | let foo = &5 - &6; | ^^^^^^^ @@ -11,12 +11,20 @@ LL | let foo = 5 - 6; | ^ ^ error: taken reference of right operand - --> $DIR/op_ref.rs:18:8 + --> $DIR/op_ref.rs:20:8 | LL | if b < &a { | ^^^^-- | | | help: use the right value directly: `a` -error: aborting due to 2 previous errors +error: taken reference of right operand + --> $DIR/op_ref.rs:57:13 + | +LL | let z = x & &y; + | ^^^^-- + | | + | help: use the right value directly: `y` + +error: aborting due to 3 previous errors