op_ref: Move tests out of eq_op file

This commit is contained in:
Manish Goregaokar 2019-09-20 14:54:16 +09:00
parent d513a0b0a1
commit 49adc99aed
4 changed files with 84 additions and 84 deletions

View File

@ -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

View File

@ -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

View File

@ -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<i32> = 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;
}

View File

@ -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