Skip to content

Commit b03370b

Browse files
authored
Add a reason to/remove some //@no-rustfix annotations (#14839)
changelog: none
2 parents 618ccd7 + 19e967c commit b03370b

27 files changed

+267
-165
lines changed

tests/ui/assign_ops.fixed

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#![allow(clippy::useless_vec)]
2+
#![warn(clippy::assign_op_pattern)]
3+
14
use core::num::Wrapping;
5+
use std::ops::{Mul, MulAssign};
26

3-
#[allow(dead_code, unused_assignments, clippy::useless_vec)]
4-
#[warn(clippy::assign_op_pattern)]
57
fn main() {
68
let mut a = 5;
79
a += 1;
@@ -39,3 +41,35 @@ fn main() {
3941
v[0] = v[0] + v[1];
4042
let _ = || v[0] = v[0] + v[1];
4143
}
44+
45+
fn cow_add_assign() {
46+
use std::borrow::Cow;
47+
let mut buf = Cow::Owned(String::from("bar"));
48+
let cows = Cow::Borrowed("foo");
49+
50+
// this can be linted
51+
buf += cows.clone();
52+
//~^ assign_op_pattern
53+
54+
// this should not as cow<str> Add is not commutative
55+
buf = cows + buf;
56+
}
57+
58+
// check that we don't lint on op assign impls, because that's just the way to impl them
59+
60+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
61+
pub struct Wrap(i64);
62+
63+
impl Mul<i64> for Wrap {
64+
type Output = Self;
65+
66+
fn mul(self, rhs: i64) -> Self {
67+
Wrap(self.0 * rhs)
68+
}
69+
}
70+
71+
impl MulAssign<i64> for Wrap {
72+
fn mul_assign(&mut self, rhs: i64) {
73+
*self = *self * rhs
74+
}
75+
}

tests/ui/assign_ops.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#![allow(clippy::useless_vec)]
2+
#![warn(clippy::assign_op_pattern)]
3+
14
use core::num::Wrapping;
5+
use std::ops::{Mul, MulAssign};
26

3-
#[allow(dead_code, unused_assignments, clippy::useless_vec)]
4-
#[warn(clippy::assign_op_pattern)]
57
fn main() {
68
let mut a = 5;
79
a = a + 1;
@@ -39,3 +41,35 @@ fn main() {
3941
v[0] = v[0] + v[1];
4042
let _ = || v[0] = v[0] + v[1];
4143
}
44+
45+
fn cow_add_assign() {
46+
use std::borrow::Cow;
47+
let mut buf = Cow::Owned(String::from("bar"));
48+
let cows = Cow::Borrowed("foo");
49+
50+
// this can be linted
51+
buf = buf + cows.clone();
52+
//~^ assign_op_pattern
53+
54+
// this should not as cow<str> Add is not commutative
55+
buf = cows + buf;
56+
}
57+
58+
// check that we don't lint on op assign impls, because that's just the way to impl them
59+
60+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
61+
pub struct Wrap(i64);
62+
63+
impl Mul<i64> for Wrap {
64+
type Output = Self;
65+
66+
fn mul(self, rhs: i64) -> Self {
67+
Wrap(self.0 * rhs)
68+
}
69+
}
70+
71+
impl MulAssign<i64> for Wrap {
72+
fn mul_assign(&mut self, rhs: i64) {
73+
*self = *self * rhs
74+
}
75+
}

tests/ui/assign_ops.stderr

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: manual implementation of an assign operation
2-
--> tests/ui/assign_ops.rs:7:5
2+
--> tests/ui/assign_ops.rs:9:5
33
|
44
LL | a = a + 1;
55
| ^^^^^^^^^ help: replace it with: `a += 1`
@@ -8,64 +8,70 @@ LL | a = a + 1;
88
= help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]`
99

1010
error: manual implementation of an assign operation
11-
--> tests/ui/assign_ops.rs:9:5
11+
--> tests/ui/assign_ops.rs:11:5
1212
|
1313
LL | a = 1 + a;
1414
| ^^^^^^^^^ help: replace it with: `a += 1`
1515

1616
error: manual implementation of an assign operation
17-
--> tests/ui/assign_ops.rs:11:5
17+
--> tests/ui/assign_ops.rs:13:5
1818
|
1919
LL | a = a - 1;
2020
| ^^^^^^^^^ help: replace it with: `a -= 1`
2121

2222
error: manual implementation of an assign operation
23-
--> tests/ui/assign_ops.rs:13:5
23+
--> tests/ui/assign_ops.rs:15:5
2424
|
2525
LL | a = a * 99;
2626
| ^^^^^^^^^^ help: replace it with: `a *= 99`
2727

2828
error: manual implementation of an assign operation
29-
--> tests/ui/assign_ops.rs:15:5
29+
--> tests/ui/assign_ops.rs:17:5
3030
|
3131
LL | a = 42 * a;
3232
| ^^^^^^^^^^ help: replace it with: `a *= 42`
3333

3434
error: manual implementation of an assign operation
35-
--> tests/ui/assign_ops.rs:17:5
35+
--> tests/ui/assign_ops.rs:19:5
3636
|
3737
LL | a = a / 2;
3838
| ^^^^^^^^^ help: replace it with: `a /= 2`
3939

4040
error: manual implementation of an assign operation
41-
--> tests/ui/assign_ops.rs:19:5
41+
--> tests/ui/assign_ops.rs:21:5
4242
|
4343
LL | a = a % 5;
4444
| ^^^^^^^^^ help: replace it with: `a %= 5`
4545

4646
error: manual implementation of an assign operation
47-
--> tests/ui/assign_ops.rs:21:5
47+
--> tests/ui/assign_ops.rs:23:5
4848
|
4949
LL | a = a & 1;
5050
| ^^^^^^^^^ help: replace it with: `a &= 1`
5151

5252
error: manual implementation of an assign operation
53-
--> tests/ui/assign_ops.rs:28:5
53+
--> tests/ui/assign_ops.rs:30:5
5454
|
5555
LL | s = s + "bla";
5656
| ^^^^^^^^^^^^^ help: replace it with: `s += "bla"`
5757

5858
error: manual implementation of an assign operation
59-
--> tests/ui/assign_ops.rs:33:5
59+
--> tests/ui/assign_ops.rs:35:5
6060
|
6161
LL | a = a + Wrapping(1u32);
6262
| ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a += Wrapping(1u32)`
6363

6464
error: manual implementation of an assign operation
65-
--> tests/ui/assign_ops.rs:36:5
65+
--> tests/ui/assign_ops.rs:38:5
6666
|
6767
LL | v[0] = v[0] + v[1];
6868
| ^^^^^^^^^^^^^^^^^^ help: replace it with: `v[0] += v[1]`
6969

70-
error: aborting due to 11 previous errors
70+
error: manual implementation of an assign operation
71+
--> tests/ui/assign_ops.rs:51:5
72+
|
73+
LL | buf = buf + cows.clone();
74+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()`
75+
76+
error: aborting due to 12 previous errors
7177

tests/ui/assign_ops2.rs

Lines changed: 0 additions & 77 deletions
This file was deleted.

tests/ui/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@no-rustfix
1+
//@no-rustfix: only some diagnostics have suggestions
22

33
#![feature(repr128)]
44
#![allow(incomplete_features)]

tests/ui/cast_size.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@revisions: 32bit 64bit
22
//@[32bit]ignore-bitwidth: 64
33
//@[64bit]ignore-bitwidth: 32
4-
//@no-rustfix
4+
//@no-rustfix: only some diagnostics have suggestions
55

66
#![warn(
77
clippy::cast_precision_loss,

tests/ui/checked_unwrap/complex_conditionals_nested.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
clippy::branches_sharing_code,
55
clippy::unnecessary_literal_unwrap
66
)]
7-
//@no-rustfix
7+
//@no-rustfix: has placeholders
88
fn test_nested() {
99
fn nested() {
1010
let x = Some(());

tests/ui/checked_unwrap/simple_conditionals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@no-rustfix: overlapping suggestions
1+
//@no-rustfix: has placeholders
22
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
33
#![allow(
44
clippy::if_same_then_else,

tests/ui/comparison_chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@no-rustfix
1+
//@no-rustfix: has placeholders
22
#![allow(dead_code)]
33
#![warn(clippy::comparison_chain)]
44

tests/ui/dbg_macro/dbg_macro_unfixable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@no-rustfix
1+
//@no-rustfix: overlapping suggestions
22
//@error-in-other-file:
33
#![warn(clippy::dbg_macro)]
44

tests/ui/double_ended_iterator_last_unfixable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@no-rustfix
1+
//@no-rustfix: requires manual changes
22
#![warn(clippy::double_ended_iterator_last)]
33

44
// Should not be linted because applying the lint would move the original iterator. This can only be

tests/ui/entry_unfixable.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
1+
#![allow(clippy::needless_pass_by_value, clippy::collapsible_if)]
22
#![warn(clippy::map_entry)]
3-
//@no-rustfix
43

54
use std::collections::HashMap;
65
use std::hash::Hash;

tests/ui/entry_unfixable.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: usage of `contains_key` followed by `insert` on a `HashMap`
2-
--> tests/ui/entry_unfixable.rs:28:13
2+
--> tests/ui/entry_unfixable.rs:27:13
33
|
44
LL | / if !self.values.contains_key(&name) {
55
LL | |
@@ -14,7 +14,7 @@ LL | | }
1414
= help: to override `-D warnings` add `#[allow(clippy::map_entry)]`
1515

1616
error: usage of `contains_key` followed by `insert` on a `HashMap`
17-
--> tests/ui/entry_unfixable.rs:43:5
17+
--> tests/ui/entry_unfixable.rs:42:5
1818
|
1919
LL | / if hm.contains_key(&key) {
2020
LL | |
@@ -26,7 +26,7 @@ LL | | }
2626
| |_____^
2727

2828
error: usage of `contains_key` followed by `insert` on a `HashMap`
29-
--> tests/ui/entry_unfixable.rs:81:13
29+
--> tests/ui/entry_unfixable.rs:80:13
3030
|
3131
LL | / if self.globals.contains_key(&name) {
3232
LL | |

tests/ui/explicit_counter_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![warn(clippy::explicit_counter_loop)]
22
#![allow(clippy::uninlined_format_args, clippy::useless_vec)]
3-
//@no-rustfix
3+
//@no-rustfix: suggestion does not remove the `+= 1`
44
fn main() {
55
let mut vec = vec![1, 2, 3, 4];
66
let mut _index = 0;

tests/ui/filter_map_bool_then_unfixable.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#![allow(clippy::question_mark, unused)]
1+
#![allow(clippy::question_mark)]
22
#![warn(clippy::filter_map_bool_then)]
3-
//@no-rustfix
43

54
fn issue11617() {
65
let mut x: Vec<usize> = vec![0; 10];

0 commit comments

Comments
 (0)