Skip to content

Commit 5004f04

Browse files
committed
added identity block test
added binding annotations for all lines
1 parent 5afc261 commit 5004f04

File tree

3 files changed

+58
-56
lines changed

3 files changed

+58
-56
lines changed

tests/ui/iter_kv_map.fixed

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![warn(clippy::iter_kv_map)]
44
#![allow(clippy::redundant_clone)]
55
#![allow(clippy::suspicious_map)]
6+
#![allow(clippy::map_identity)]
67

78
use std::collections::{BTreeMap, HashMap};
89

@@ -23,18 +24,18 @@ fn main() {
2324
let _ = map.clone().into_values().map(|val| val + 2).collect::<Vec<_>>();
2425

2526
let _ = map.clone().values().collect::<Vec<_>>();
26-
map.keys().filter(|x| *x % 2 == 0).count();
27+
let _ = map.keys().filter(|x| *x % 2 == 0).count();
2728

2829
// Don't lint
29-
map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
30-
map.iter().map(get_key).collect::<Vec<_>>();
30+
let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
31+
let _ = map.iter().map(get_key).collect::<Vec<_>>();
3132

3233
// Linting the following could be an improvement to the lint
3334
// map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
3435

3536
// Lint
36-
map.keys().map(|key| key * 9).count();
37-
map.values().map(|value| value * 17).count();
37+
let _ = map.keys().map(|key| key * 9).count();
38+
let _ = map.values().map(|value| value * 17).count();
3839

3940
let map: BTreeMap<u32, u32> = BTreeMap::new();
4041

@@ -50,16 +51,16 @@ fn main() {
5051
let _ = map.clone().into_values().map(|val| val + 2).collect::<Vec<_>>();
5152

5253
let _ = map.clone().values().collect::<Vec<_>>();
53-
map.keys().filter(|x| *x % 2 == 0).count();
54+
let _ = map.keys().filter(|x| *x % 2 == 0).count();
5455

5556
// Don't lint
56-
map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
57-
map.iter().map(get_key).collect::<Vec<_>>();
57+
let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
58+
let _ = map.iter().map(get_key).collect::<Vec<_>>();
5859

5960
// Linting the following could be an improvement to the lint
6061
// map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
6162

6263
// Lint
63-
map.keys().map(|key| key * 9).count();
64-
map.values().map(|value| value * 17).count();
64+
let _ = map.keys().map(|key| key * 9).count();
65+
let _ = map.values().map(|value| value * 17).count();
6566
}

tests/ui/iter_kv_map.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![warn(clippy::iter_kv_map)]
44
#![allow(clippy::redundant_clone)]
55
#![allow(clippy::suspicious_map)]
6+
#![allow(clippy::map_identity)]
67

78
use std::collections::{BTreeMap, HashMap};
89

@@ -23,18 +24,18 @@ fn main() {
2324
let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
2425

2526
let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
26-
map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
27+
let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
2728

2829
// Don't lint
29-
map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
30-
map.iter().map(get_key).collect::<Vec<_>>();
30+
let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
31+
let _ = map.iter().map(get_key).collect::<Vec<_>>();
3132

3233
// Linting the following could be an improvement to the lint
3334
// map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
3435

3536
// Lint
36-
map.iter().map(|(key, _value)| key * 9).count();
37-
map.iter().map(|(_key, value)| value * 17).count();
37+
let _ = map.iter().map(|(key, _value)| key * 9).count();
38+
let _ = map.iter().map(|(_key, value)| value * 17).count();
3839

3940
let map: BTreeMap<u32, u32> = BTreeMap::new();
4041

@@ -50,16 +51,16 @@ fn main() {
5051
let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
5152

5253
let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
53-
map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
54+
let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
5455

5556
// Don't lint
56-
map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
57-
map.iter().map(get_key).collect::<Vec<_>>();
57+
let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
58+
let _ = map.iter().map(get_key).collect::<Vec<_>>();
5859

5960
// Linting the following could be an improvement to the lint
6061
// map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
6162

6263
// Lint
63-
map.iter().map(|(key, _value)| key * 9).count();
64-
map.iter().map(|(_key, value)| value * 17).count();
64+
let _ = map.iter().map(|(key, _value)| key * 9).count();
65+
let _ = map.iter().map(|(_key, value)| value * 17).count();
6566
}

tests/ui/iter_kv_map.stderr

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,148 @@
11
error: iterating on a map's keys
2-
--> $DIR/iter_kv_map.rs:14:13
2+
--> $DIR/iter_kv_map.rs:15:13
33
|
44
LL | let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
66
|
77
= note: `-D clippy::iter-kv-map` implied by `-D warnings`
88

99
error: iterating on a map's values
10-
--> $DIR/iter_kv_map.rs:15:13
10+
--> $DIR/iter_kv_map.rs:16:13
1111
|
1212
LL | let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()`
1414

1515
error: iterating on a map's values
16-
--> $DIR/iter_kv_map.rs:16:13
16+
--> $DIR/iter_kv_map.rs:17:13
1717
|
1818
LL | let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)`
2020

2121
error: iterating on a map's values
22-
--> $DIR/iter_kv_map.rs:17:13
22+
--> $DIR/iter_kv_map.rs:18:13
2323
|
2424
LL | let _ = map.iter().map(|(_, val)| {val}).collect::<Vec<_>>();
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|val| {val})`
2626

2727
error: iterating on a map's keys
28-
--> $DIR/iter_kv_map.rs:19:13
28+
--> $DIR/iter_kv_map.rs:20:13
2929
|
3030
LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()`
3232

3333
error: iterating on a map's keys
34-
--> $DIR/iter_kv_map.rs:20:13
34+
--> $DIR/iter_kv_map.rs:21:13
3535
|
3636
LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)`
3838

3939
error: iterating on a map's values
40-
--> $DIR/iter_kv_map.rs:22:13
40+
--> $DIR/iter_kv_map.rs:23:13
4141
|
4242
LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>();
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()`
4444

4545
error: iterating on a map's values
46-
--> $DIR/iter_kv_map.rs:23:13
46+
--> $DIR/iter_kv_map.rs:24:13
4747
|
4848
LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)`
5050

5151
error: iterating on a map's values
52-
--> $DIR/iter_kv_map.rs:25:13
52+
--> $DIR/iter_kv_map.rs:26:13
5353
|
5454
LL | let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()`
5656

5757
error: iterating on a map's keys
58-
--> $DIR/iter_kv_map.rs:26:5
58+
--> $DIR/iter_kv_map.rs:27:13
5959
|
60-
LL | map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
61-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
60+
LL | let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
6262

6363
error: iterating on a map's keys
64-
--> $DIR/iter_kv_map.rs:36:5
64+
--> $DIR/iter_kv_map.rs:37:13
6565
|
66-
LL | map.iter().map(|(key, _value)| key * 9).count();
67-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
66+
LL | let _ = map.iter().map(|(key, _value)| key * 9).count();
67+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
6868

6969
error: iterating on a map's values
70-
--> $DIR/iter_kv_map.rs:37:5
70+
--> $DIR/iter_kv_map.rs:38:13
7171
|
72-
LL | map.iter().map(|(_key, value)| value * 17).count();
73-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
72+
LL | let _ = map.iter().map(|(_key, value)| value * 17).count();
73+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
7474

7575
error: iterating on a map's keys
76-
--> $DIR/iter_kv_map.rs:41:13
76+
--> $DIR/iter_kv_map.rs:42:13
7777
|
7878
LL | let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
8080

8181
error: iterating on a map's values
82-
--> $DIR/iter_kv_map.rs:42:13
82+
--> $DIR/iter_kv_map.rs:43:13
8383
|
8484
LL | let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
8585
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()`
8686

8787
error: iterating on a map's values
88-
--> $DIR/iter_kv_map.rs:43:13
88+
--> $DIR/iter_kv_map.rs:44:13
8989
|
9090
LL | let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
9191
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)`
9292

9393
error: iterating on a map's values
94-
--> $DIR/iter_kv_map.rs:44:13
94+
--> $DIR/iter_kv_map.rs:45:13
9595
|
9696
LL | let _ = map.iter().map(|(_, val)| {val}).collect::<Vec<_>>();
9797
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|val| {val})`
9898

9999
error: iterating on a map's keys
100-
--> $DIR/iter_kv_map.rs:46:13
100+
--> $DIR/iter_kv_map.rs:47:13
101101
|
102102
LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
103103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()`
104104

105105
error: iterating on a map's keys
106-
--> $DIR/iter_kv_map.rs:47:13
106+
--> $DIR/iter_kv_map.rs:48:13
107107
|
108108
LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
109109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)`
110110

111111
error: iterating on a map's values
112-
--> $DIR/iter_kv_map.rs:49:13
112+
--> $DIR/iter_kv_map.rs:50:13
113113
|
114114
LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>();
115115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()`
116116

117117
error: iterating on a map's values
118-
--> $DIR/iter_kv_map.rs:50:13
118+
--> $DIR/iter_kv_map.rs:51:13
119119
|
120120
LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
121121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)`
122122

123123
error: iterating on a map's values
124-
--> $DIR/iter_kv_map.rs:52:13
124+
--> $DIR/iter_kv_map.rs:53:13
125125
|
126126
LL | let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
127127
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()`
128128

129129
error: iterating on a map's keys
130-
--> $DIR/iter_kv_map.rs:53:5
130+
--> $DIR/iter_kv_map.rs:54:13
131131
|
132-
LL | map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
133-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
132+
LL | let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
133+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
134134

135135
error: iterating on a map's keys
136-
--> $DIR/iter_kv_map.rs:63:5
136+
--> $DIR/iter_kv_map.rs:64:13
137137
|
138-
LL | map.iter().map(|(key, _value)| key * 9).count();
139-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
138+
LL | let _ = map.iter().map(|(key, _value)| key * 9).count();
139+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
140140

141141
error: iterating on a map's values
142-
--> $DIR/iter_kv_map.rs:64:5
142+
--> $DIR/iter_kv_map.rs:65:13
143143
|
144-
LL | map.iter().map(|(_key, value)| value * 17).count();
145-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
144+
LL | let _ = map.iter().map(|(_key, value)| value * 17).count();
145+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
146146

147147
error: aborting due to 24 previous errors
148148

0 commit comments

Comments
 (0)