added identity block test

added binding annotations for all lines
This commit is contained in:
Kartavya Vashishtha 2022-09-15 09:46:01 +05:30
parent 5afc261c66
commit 5004f04ecc
No known key found for this signature in database
GPG key ID: A50012C2324E5DF0
3 changed files with 58 additions and 56 deletions

View file

@ -3,6 +3,7 @@
#![warn(clippy::iter_kv_map)] #![warn(clippy::iter_kv_map)]
#![allow(clippy::redundant_clone)] #![allow(clippy::redundant_clone)]
#![allow(clippy::suspicious_map)] #![allow(clippy::suspicious_map)]
#![allow(clippy::map_identity)]
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
@ -23,18 +24,18 @@ fn main() {
let _ = map.clone().into_values().map(|val| val + 2).collect::<Vec<_>>(); let _ = map.clone().into_values().map(|val| val + 2).collect::<Vec<_>>();
let _ = map.clone().values().collect::<Vec<_>>(); let _ = map.clone().values().collect::<Vec<_>>();
map.keys().filter(|x| *x % 2 == 0).count(); let _ = map.keys().filter(|x| *x % 2 == 0).count();
// Don't lint // Don't lint
map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count(); let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
map.iter().map(get_key).collect::<Vec<_>>(); let _ = map.iter().map(get_key).collect::<Vec<_>>();
// Linting the following could be an improvement to the lint // Linting the following could be an improvement to the lint
// map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count(); // map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
// Lint // Lint
map.keys().map(|key| key * 9).count(); let _ = map.keys().map(|key| key * 9).count();
map.values().map(|value| value * 17).count(); let _ = map.values().map(|value| value * 17).count();
let map: BTreeMap<u32, u32> = BTreeMap::new(); let map: BTreeMap<u32, u32> = BTreeMap::new();
@ -50,16 +51,16 @@ fn main() {
let _ = map.clone().into_values().map(|val| val + 2).collect::<Vec<_>>(); let _ = map.clone().into_values().map(|val| val + 2).collect::<Vec<_>>();
let _ = map.clone().values().collect::<Vec<_>>(); let _ = map.clone().values().collect::<Vec<_>>();
map.keys().filter(|x| *x % 2 == 0).count(); let _ = map.keys().filter(|x| *x % 2 == 0).count();
// Don't lint // Don't lint
map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count(); let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
map.iter().map(get_key).collect::<Vec<_>>(); let _ = map.iter().map(get_key).collect::<Vec<_>>();
// Linting the following could be an improvement to the lint // Linting the following could be an improvement to the lint
// map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count(); // map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
// Lint // Lint
map.keys().map(|key| key * 9).count(); let _ = map.keys().map(|key| key * 9).count();
map.values().map(|value| value * 17).count(); let _ = map.values().map(|value| value * 17).count();
} }

View file

@ -3,6 +3,7 @@
#![warn(clippy::iter_kv_map)] #![warn(clippy::iter_kv_map)]
#![allow(clippy::redundant_clone)] #![allow(clippy::redundant_clone)]
#![allow(clippy::suspicious_map)] #![allow(clippy::suspicious_map)]
#![allow(clippy::map_identity)]
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
@ -23,18 +24,18 @@ fn main() {
let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>(); let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>(); let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count(); let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
// Don't lint // Don't lint
map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count(); let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
map.iter().map(get_key).collect::<Vec<_>>(); let _ = map.iter().map(get_key).collect::<Vec<_>>();
// Linting the following could be an improvement to the lint // Linting the following could be an improvement to the lint
// map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count(); // map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
// Lint // Lint
map.iter().map(|(key, _value)| key * 9).count(); let _ = map.iter().map(|(key, _value)| key * 9).count();
map.iter().map(|(_key, value)| value * 17).count(); let _ = map.iter().map(|(_key, value)| value * 17).count();
let map: BTreeMap<u32, u32> = BTreeMap::new(); let map: BTreeMap<u32, u32> = BTreeMap::new();
@ -50,16 +51,16 @@ fn main() {
let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>(); let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>(); let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count(); let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
// Don't lint // Don't lint
map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count(); let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
map.iter().map(get_key).collect::<Vec<_>>(); let _ = map.iter().map(get_key).collect::<Vec<_>>();
// Linting the following could be an improvement to the lint // Linting the following could be an improvement to the lint
// map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count(); // map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
// Lint // Lint
map.iter().map(|(key, _value)| key * 9).count(); let _ = map.iter().map(|(key, _value)| key * 9).count();
map.iter().map(|(_key, value)| value * 17).count(); let _ = map.iter().map(|(_key, value)| value * 17).count();
} }

View file

@ -1,5 +1,5 @@
error: iterating on a map's keys error: iterating on a map's keys
--> $DIR/iter_kv_map.rs:14:13 --> $DIR/iter_kv_map.rs:15:13
| |
LL | let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>(); LL | let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
@ -7,142 +7,142 @@ LL | let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
= note: `-D clippy::iter-kv-map` implied by `-D warnings` = note: `-D clippy::iter-kv-map` implied by `-D warnings`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:15:13 --> $DIR/iter_kv_map.rs:16:13
| |
LL | let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>(); LL | let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:16:13 --> $DIR/iter_kv_map.rs:17:13
| |
LL | let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>(); LL | let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:17:13 --> $DIR/iter_kv_map.rs:18:13
| |
LL | let _ = map.iter().map(|(_, val)| {val}).collect::<Vec<_>>(); LL | let _ = map.iter().map(|(_, val)| {val}).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|val| {val})` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|val| {val})`
error: iterating on a map's keys error: iterating on a map's keys
--> $DIR/iter_kv_map.rs:19:13 --> $DIR/iter_kv_map.rs:20:13
| |
LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>(); LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()`
error: iterating on a map's keys error: iterating on a map's keys
--> $DIR/iter_kv_map.rs:20:13 --> $DIR/iter_kv_map.rs:21:13
| |
LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>(); LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:22:13 --> $DIR/iter_kv_map.rs:23:13
| |
LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>(); LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:23:13 --> $DIR/iter_kv_map.rs:24:13
| |
LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>(); LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:25:13 --> $DIR/iter_kv_map.rs:26:13
| |
LL | let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>(); LL | let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()`
error: iterating on a map's keys error: iterating on a map's keys
--> $DIR/iter_kv_map.rs:26:5 --> $DIR/iter_kv_map.rs:27:13
| |
LL | map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count(); LL | let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
error: iterating on a map's keys error: iterating on a map's keys
--> $DIR/iter_kv_map.rs:36:5 --> $DIR/iter_kv_map.rs:37:13
| |
LL | map.iter().map(|(key, _value)| key * 9).count(); LL | let _ = map.iter().map(|(key, _value)| key * 9).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:37:5 --> $DIR/iter_kv_map.rs:38:13
| |
LL | map.iter().map(|(_key, value)| value * 17).count(); LL | let _ = map.iter().map(|(_key, value)| value * 17).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
error: iterating on a map's keys error: iterating on a map's keys
--> $DIR/iter_kv_map.rs:41:13 --> $DIR/iter_kv_map.rs:42:13
| |
LL | let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>(); LL | let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:42:13 --> $DIR/iter_kv_map.rs:43:13
| |
LL | let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>(); LL | let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:43:13 --> $DIR/iter_kv_map.rs:44:13
| |
LL | let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>(); LL | let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:44:13 --> $DIR/iter_kv_map.rs:45:13
| |
LL | let _ = map.iter().map(|(_, val)| {val}).collect::<Vec<_>>(); LL | let _ = map.iter().map(|(_, val)| {val}).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|val| {val})` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|val| {val})`
error: iterating on a map's keys error: iterating on a map's keys
--> $DIR/iter_kv_map.rs:46:13 --> $DIR/iter_kv_map.rs:47:13
| |
LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>(); LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()`
error: iterating on a map's keys error: iterating on a map's keys
--> $DIR/iter_kv_map.rs:47:13 --> $DIR/iter_kv_map.rs:48:13
| |
LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>(); LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:49:13 --> $DIR/iter_kv_map.rs:50:13
| |
LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>(); LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:50:13 --> $DIR/iter_kv_map.rs:51:13
| |
LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>(); LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:52:13 --> $DIR/iter_kv_map.rs:53:13
| |
LL | let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>(); LL | let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()`
error: iterating on a map's keys error: iterating on a map's keys
--> $DIR/iter_kv_map.rs:53:5 --> $DIR/iter_kv_map.rs:54:13
| |
LL | map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count(); LL | let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
error: iterating on a map's keys error: iterating on a map's keys
--> $DIR/iter_kv_map.rs:63:5 --> $DIR/iter_kv_map.rs:64:13
| |
LL | map.iter().map(|(key, _value)| key * 9).count(); LL | let _ = map.iter().map(|(key, _value)| key * 9).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
error: iterating on a map's values error: iterating on a map's values
--> $DIR/iter_kv_map.rs:64:5 --> $DIR/iter_kv_map.rs:65:13
| |
LL | map.iter().map(|(_key, value)| value * 17).count(); LL | let _ = map.iter().map(|(_key, value)| value * 17).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
error: aborting due to 24 previous errors error: aborting due to 24 previous errors