Skip to content

Commit 31e5e76

Browse files
committed
clippy: uibless new test output
In a couple of cases, adjust the test file, because otherwise the file produces: ``` error: failed to apply suggestions for tests/ui/iter_overeager_cloned.rs with rustfix cannot replace slice of data that was already replaced Add //@no-rustfix to the test file to ignore rustfix suggestions ```
1 parent 022361c commit 31e5e76

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

src/tools/clippy/tests/ui/iter_overeager_cloned.fixed

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ fn main() {
1313

1414
let _: Option<String> = vec.iter().chain(vec.iter()).next().cloned();
1515

16-
let _: usize = vec.iter().filter(|x| x == &"2").count();
16+
let _: usize = vec.iter().filter(|x| x == "2").count();
1717

1818
let _: Vec<_> = vec.iter().take(2).cloned().collect();
1919

2020
let _: Vec<_> = vec.iter().skip(2).cloned().collect();
2121

22-
let _ = vec.iter().filter(|x| x == &"2").nth(2).cloned();
22+
let _ = vec.iter().filter(|x| x == "2").nth(2).cloned();
2323

2424
let _ = [Some(Some("str".to_string())), Some(Some("str".to_string()))]
2525
.iter()
@@ -46,7 +46,7 @@ fn main() {
4646
iter: impl Iterator<Item = &'a (&'a u32, String)> + 'a,
4747
target: String,
4848
) -> impl Iterator<Item = (&'a u32, String)> + 'a {
49-
iter.filter(move |&(&a, b)| a == 1 && b == &target).cloned()
49+
iter.filter(move |&(&a, b)| a == 1 && b == target).cloned()
5050
}
5151

5252
{
@@ -57,7 +57,7 @@ fn main() {
5757
}
5858

5959
fn bar<'a>(iter: impl Iterator<Item = &'a S<'a>> + 'a, target: String) -> impl Iterator<Item = S<'a>> + 'a {
60-
iter.filter(move |&S { a, b }| **a == 1 && b == &target).cloned()
60+
iter.filter(move |&S { a, b }| **a == 1 && b == target).cloned()
6161
}
6262
}
6363

src/tools/clippy/tests/ui/iter_overeager_cloned.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn main() {
4747
iter: impl Iterator<Item = &'a (&'a u32, String)> + 'a,
4848
target: String,
4949
) -> impl Iterator<Item = (&'a u32, String)> + 'a {
50-
iter.cloned().filter(move |(&a, b)| a == 1 && b == &target)
50+
iter.cloned().filter(move |(&a, b)| a == 1 && b == target)
5151
}
5252

5353
{
@@ -58,7 +58,7 @@ fn main() {
5858
}
5959

6060
fn bar<'a>(iter: impl Iterator<Item = &'a S<'a>> + 'a, target: String) -> impl Iterator<Item = S<'a>> + 'a {
61-
iter.cloned().filter(move |S { a, b }| **a == 1 && b == &target)
61+
iter.cloned().filter(move |S { a, b }| **a == 1 && b == target)
6262
}
6363
}
6464

src/tools/clippy/tests/ui/iter_overeager_cloned.stderr

+26-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ LL | let _: usize = vec.iter().filter(|x| x == &"2").cloned().count();
2828
= note: `-D clippy::redundant-clone` implied by `-D warnings`
2929
= help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]`
3030

31+
error: taken reference of right operand
32+
--> tests/ui/iter_overeager_cloned.rs:16:42
33+
|
34+
LL | let _: usize = vec.iter().filter(|x| x == &"2").cloned().count();
35+
| ^^^^^----
36+
| |
37+
| help: use the right value directly: `"2"`
38+
|
39+
= note: `-D clippy::op-ref` implied by `-D warnings`
40+
= help: to override `-D warnings` add `#[allow(clippy::op_ref)]`
41+
3142
error: unnecessarily eager cloning of iterator items
3243
--> tests/ui/iter_overeager_cloned.rs:18:21
3344
|
@@ -52,6 +63,14 @@ LL | let _ = vec.iter().filter(|x| x == &"2").cloned().nth(2);
5263
| |
5364
| help: try: `.nth(2).cloned()`
5465

66+
error: taken reference of right operand
67+
--> tests/ui/iter_overeager_cloned.rs:22:35
68+
|
69+
LL | let _ = vec.iter().filter(|x| x == &"2").cloned().nth(2);
70+
| ^^^^^----
71+
| |
72+
| help: use the right value directly: `"2"`
73+
5574
error: unnecessarily eager cloning of iterator items
5675
--> tests/ui/iter_overeager_cloned.rs:24:13
5776
|
@@ -119,18 +138,18 @@ LL | let _ = vec.iter().cloned().find(f);
119138
error: unnecessarily eager cloning of iterator items
120139
--> tests/ui/iter_overeager_cloned.rs:50:9
121140
|
122-
LL | iter.cloned().filter(move |(&a, b)| a == 1 && b == &target)
123-
| ^^^^-------------------------------------------------------
141+
LL | iter.cloned().filter(move |(&a, b)| a == 1 && b == target)
142+
| ^^^^------------------------------------------------------
124143
| |
125-
| help: try: `.filter(move |&(&a, b)| a == 1 && b == &target).cloned()`
144+
| help: try: `.filter(move |&(&a, b)| a == 1 && b == target).cloned()`
126145

127146
error: unnecessarily eager cloning of iterator items
128147
--> tests/ui/iter_overeager_cloned.rs:61:13
129148
|
130-
LL | iter.cloned().filter(move |S { a, b }| **a == 1 && b == &target)
131-
| ^^^^------------------------------------------------------------
149+
LL | iter.cloned().filter(move |S { a, b }| **a == 1 && b == target)
150+
| ^^^^-----------------------------------------------------------
132151
| |
133-
| help: try: `.filter(move |&S { a, b }| **a == 1 && b == &target).cloned()`
152+
| help: try: `.filter(move |&S { a, b }| **a == 1 && b == target).cloned()`
134153

135154
error: unneeded cloning of iterator items
136155
--> tests/ui/iter_overeager_cloned.rs:65:13
@@ -164,5 +183,5 @@ LL | let _ = vec.iter().cloned().any(|x| x.len() == 1);
164183
| |
165184
| help: try: `.any(|x| x.len() == 1)`
166185

167-
error: aborting due to 19 previous errors
186+
error: aborting due to 21 previous errors
168187

src/tools/clippy/tests/ui/op_ref.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() {
1818
let a = "a".to_string();
1919
let b = "a";
2020

21-
if b < &a {
21+
if b < a {
2222
println!("OK");
2323
}
2424

src/tools/clippy/tests/ui/op_ref.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ help: use the values directly
1111
LL | let foo = 5 - 6;
1212
| ~ ~
1313

14+
error: taken reference of right operand
15+
--> tests/ui/op_ref.rs:21:8
16+
|
17+
LL | if b < &a {
18+
| ^^^^--
19+
| |
20+
| help: use the right value directly: `a`
21+
1422
error: taken reference of right operand
1523
--> tests/ui/op_ref.rs:58:13
1624
|
@@ -35,5 +43,5 @@ LL | let _ = two + &three;
3543
| |
3644
| help: use the right value directly: `three`
3745

38-
error: aborting due to 4 previous errors
46+
error: aborting due to 5 previous errors
3947

0 commit comments

Comments
 (0)