Skip to content

Commit 474a880

Browse files
committed
add followup lint directions to test
1 parent c136f59 commit 474a880

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

tests/ui/iter_kv_map.fixed

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ fn main() {
2525
// Don't lint
2626
map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
2727

28+
// Linting the following could be an improvement to the lint
29+
// map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
30+
2831
// Lint
2932
map.keys().map(|key| key * 9).count();
3033
map.values().map(|value| value * 17).count();

tests/ui/iter_kv_map.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ fn main() {
2525
// Don't lint
2626
map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
2727

28+
// Linting the following could be an improvement to the lint
29+
// map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
30+
2831
// Lint
2932
map.iter().map(|(key, _value)| key * 9).count();
3033
map.iter().map(|(_key, value)| value * 17).count();

tests/ui/iter_kv_map.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,73 +49,73 @@ LL | map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
5050

5151
error: you seem to want to iterate on a map's keys
52-
--> $DIR/iter_kv_map.rs:29:5
52+
--> $DIR/iter_kv_map.rs:32:5
5353
|
5454
LL | map.iter().map(|(key, _value)| key * 9).count();
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the corresponding method: `map.keys().map(|key| key * 9)`
5656

5757
error: you seem to want to iterate on a map's values
58-
--> $DIR/iter_kv_map.rs:30:5
58+
--> $DIR/iter_kv_map.rs:33:5
5959
|
6060
LL | map.iter().map(|(_key, value)| value * 17).count();
6161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the corresponding method: `map.values().map(|value| value * 17)`
6262

6363
error: iterating on a map's keys
64-
--> $DIR/iter_kv_map.rs:34:13
64+
--> $DIR/iter_kv_map.rs:37:13
6565
|
6666
LL | let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
6868

6969
error: iterating on a map's values
70-
--> $DIR/iter_kv_map.rs:35:13
70+
--> $DIR/iter_kv_map.rs:38:13
7171
|
7272
LL | let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
7373
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()`
7474

7575
error: you seem to want to iterate on a map's values
76-
--> $DIR/iter_kv_map.rs:36:13
76+
--> $DIR/iter_kv_map.rs:39:13
7777
|
7878
LL | let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the corresponding method: `map.values().map(|v| v + 2)`
8080

8181
error: iterating on a map's keys
82-
--> $DIR/iter_kv_map.rs:38:13
82+
--> $DIR/iter_kv_map.rs:41:13
8383
|
8484
LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
8585
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()`
8686

8787
error: you seem to want to iterate on a map's keys
88-
--> $DIR/iter_kv_map.rs:39:13
88+
--> $DIR/iter_kv_map.rs:42:13
8989
|
9090
LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
9191
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the corresponding method: `map.clone().into_keys().map(|key| key + 2)`
9292

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

9999
error: you seem to want to iterate on a map's values
100-
--> $DIR/iter_kv_map.rs:42:13
100+
--> $DIR/iter_kv_map.rs:45:13
101101
|
102102
LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
103103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the corresponding method: `map.clone().into_values().map(|val| val + 2)`
104104

105105
error: iterating on a map's keys
106-
--> $DIR/iter_kv_map.rs:45:5
106+
--> $DIR/iter_kv_map.rs:48:5
107107
|
108108
LL | map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
109109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
110110

111111
error: you seem to want to iterate on a map's keys
112-
--> $DIR/iter_kv_map.rs:51:5
112+
--> $DIR/iter_kv_map.rs:54:5
113113
|
114114
LL | map.iter().map(|(key, _value)| key * 9).count();
115115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the corresponding method: `map.keys().map(|key| key * 9)`
116116

117117
error: you seem to want to iterate on a map's values
118-
--> $DIR/iter_kv_map.rs:52:5
118+
--> $DIR/iter_kv_map.rs:55:5
119119
|
120120
LL | map.iter().map(|(_key, value)| value * 17).count();
121121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the corresponding method: `map.values().map(|value| value * 17)`

0 commit comments

Comments
 (0)