Skip to content

Commit

Permalink
Auto merge of #4558 - Manishearth:suggestions, r=phansch
Browse files Browse the repository at this point in the history
Make more tests rustfixable

changelog: Fix various lint suggestions

Progress towards #3630

r? @phansch
  • Loading branch information
bors committed Sep 20, 2019
2 parents ca9e4ad + b352c2d commit 49fcdfa
Show file tree
Hide file tree
Showing 22 changed files with 678 additions and 224 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/assign_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ fn lint_misrefactored_assign_op(
long
),
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
Applicability::MachineApplicable,
Applicability::MaybeIncorrect,
);
db.span_suggestion(
expr.span,
"or",
long,
Applicability::MachineApplicable, // snippet
Applicability::MaybeIncorrect, // snippet
);
}
},
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ fn check_for_loop_reverse_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'tcx
let start_snippet = snippet(cx, start.span, "_");
let end_snippet = snippet(cx, end.span, "_");
let dots = if limits == ast::RangeLimits::Closed {
"..."
"..="
} else {
".."
};
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/deref_addrof_double_trigger.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// This test can't work with run-rustfix because it needs two passes of test+fix

#[warn(clippy::deref_addrof)]
#[allow(unused_variables)]
#[allow(unused_variables, unused_mut)]
fn main() {
let a = 10;

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/deref_addrof_double_trigger.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
error: immediately dereferencing a reference
--> $DIR/deref_addrof_double_trigger.rs:8:14
--> $DIR/deref_addrof_double_trigger.rs:10:14
|
LL | let b = **&&a;
| ^^^^ help: try this: `&a`
|
= note: `-D clippy::deref-addrof` implied by `-D warnings`

error: immediately dereferencing a reference
--> $DIR/deref_addrof_double_trigger.rs:12:17
--> $DIR/deref_addrof_double_trigger.rs:14:17
|
LL | let y = *&mut x;
| ^^^^^^^ help: try this: `x`

error: immediately dereferencing a reference
--> $DIR/deref_addrof_double_trigger.rs:19:18
--> $DIR/deref_addrof_double_trigger.rs:21:18
|
LL | let y = **&mut &mut x;
| ^^^^^^^^^^^^ help: try this: `&mut x`
Expand Down
39 changes: 2 additions & 37 deletions tests/ui/eq_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#[warn(clippy::eq_op)]
#[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(clippy::nonminimal_bool)]
#[allow(unused)]
fn main() {
// simple values and comparisons
1 == 1;
Expand Down Expand Up @@ -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
Expand Down
104 changes: 28 additions & 76 deletions tests/ui/eq_op.stderr
Original file line number Diff line number Diff line change
@@ -1,214 +1,166 @@
error: this boolean expression can be simplified
--> $DIR/eq_op.rs:35:5
|
LL | true && true;
| ^^^^^^^^^^^^ help: try: `true`
|
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`

error: this boolean expression can be simplified
--> $DIR/eq_op.rs:37:5
|
LL | true || true;
| ^^^^^^^^^^^^ help: try: `true`

error: this boolean expression can be simplified
--> $DIR/eq_op.rs:43:5
|
LL | a == b && b == a;
| ^^^^^^^^^^^^^^^^ help: try: `a == b`

error: this boolean expression can be simplified
--> $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:45:5
|
LL | a < b && b > a;
| ^^^^^^^^^^^^^^ help: try: `a < b`

error: this boolean expression can be simplified
--> $DIR/eq_op.rs:46: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;
| ^^^^^^
|
= 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 27 previous errors

Loading

0 comments on commit 49fcdfa

Please sign in to comment.