about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKartavya Vashishtha <sendtokartavya@gmail.com>2022-09-15 09:46:01 +0530
committerKartavya Vashishtha <sendtokartavya@gmail.com>2022-09-15 09:46:01 +0530
commit5004f04eccabe954e489b4ca85ab0692a93ff3f0 (patch)
treea91db19094496dbc24764b7c0ca127397f9fbb58
parent5afc261c66896ed3d14f9d9eccbc7a1090d379d3 (diff)
downloadrust-5004f04eccabe954e489b4ca85ab0692a93ff3f0.tar.gz
rust-5004f04eccabe954e489b4ca85ab0692a93ff3f0.zip
added identity block test
added binding annotations for all lines
-rw-r--r--tests/ui/iter_kv_map.fixed21
-rw-r--r--tests/ui/iter_kv_map.rs21
-rw-r--r--tests/ui/iter_kv_map.stderr72
3 files changed, 58 insertions, 56 deletions
diff --git a/tests/ui/iter_kv_map.fixed b/tests/ui/iter_kv_map.fixed
index cf1292ecc23..40e63cc2856 100644
--- a/tests/ui/iter_kv_map.fixed
+++ b/tests/ui/iter_kv_map.fixed
@@ -3,6 +3,7 @@
 #![warn(clippy::iter_kv_map)]
 #![allow(clippy::redundant_clone)]
 #![allow(clippy::suspicious_map)]
+#![allow(clippy::map_identity)]
 
 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().values().collect::<Vec<_>>();
-    map.keys().filter(|x| *x % 2 == 0).count();
+    let _ = map.keys().filter(|x| *x % 2 == 0).count();
 
     // Don't lint
-    map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
-    map.iter().map(get_key).collect::<Vec<_>>();
+    let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
+    let _ = map.iter().map(get_key).collect::<Vec<_>>();
 
     // Linting the following could be an improvement to the lint
     // map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
 
     // Lint
-    map.keys().map(|key| key * 9).count();
-    map.values().map(|value| value * 17).count();
+    let _ = map.keys().map(|key| key * 9).count();
+    let _ = map.values().map(|value| value * 17).count();
 
     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().values().collect::<Vec<_>>();
-    map.keys().filter(|x| *x % 2 == 0).count();
+    let _ = map.keys().filter(|x| *x % 2 == 0).count();
 
     // Don't lint
-    map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
-    map.iter().map(get_key).collect::<Vec<_>>();
+    let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
+    let _ = map.iter().map(get_key).collect::<Vec<_>>();
 
     // Linting the following could be an improvement to the lint
     // map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
 
     // Lint
-    map.keys().map(|key| key * 9).count();
-    map.values().map(|value| value * 17).count();
+    let _ = map.keys().map(|key| key * 9).count();
+    let _ = map.values().map(|value| value * 17).count();
 }
diff --git a/tests/ui/iter_kv_map.rs b/tests/ui/iter_kv_map.rs
index b27e559e8e5..5f662faa127 100644
--- a/tests/ui/iter_kv_map.rs
+++ b/tests/ui/iter_kv_map.rs
@@ -3,6 +3,7 @@
 #![warn(clippy::iter_kv_map)]
 #![allow(clippy::redundant_clone)]
 #![allow(clippy::suspicious_map)]
+#![allow(clippy::map_identity)]
 
 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().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
-    map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
-    map.iter().map(get_key).collect::<Vec<_>>();
+    let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
+    let _ = map.iter().map(get_key).collect::<Vec<_>>();
 
     // Linting the following could be an improvement to the lint
     // map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
 
     // Lint
-    map.iter().map(|(key, _value)| key * 9).count();
-    map.iter().map(|(_key, value)| value * 17).count();
+    let _ = map.iter().map(|(key, _value)| key * 9).count();
+    let _ = map.iter().map(|(_key, value)| value * 17).count();
 
     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().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
-    map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
-    map.iter().map(get_key).collect::<Vec<_>>();
+    let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
+    let _ = map.iter().map(get_key).collect::<Vec<_>>();
 
     // Linting the following could be an improvement to the lint
     // map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
 
     // Lint
-    map.iter().map(|(key, _value)| key * 9).count();
-    map.iter().map(|(_key, value)| value * 17).count();
+    let _ = map.iter().map(|(key, _value)| key * 9).count();
+    let _ = map.iter().map(|(_key, value)| value * 17).count();
 }
diff --git a/tests/ui/iter_kv_map.stderr b/tests/ui/iter_kv_map.stderr
index a6697e423e7..7a0c10592a1 100644
--- a/tests/ui/iter_kv_map.stderr
+++ b/tests/ui/iter_kv_map.stderr
@@ -1,5 +1,5 @@
 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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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`
 
 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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)`
 
 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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|val| {val})`
 
 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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)`
 
 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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)`
 
 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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()`
 
 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();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
+LL |     let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.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();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
+LL |     let _ = map.iter().map(|(key, _value)| key * 9).count();
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
 
 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();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
+LL |     let _ = map.iter().map(|(_key, value)| value * 17).count();
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
 
 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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
 
 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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)`
 
 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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|val| {val})`
 
 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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)`
 
 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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)`
 
 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<_>>();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()`
 
 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();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
+LL |     let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.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();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
+LL |     let _ = map.iter().map(|(key, _value)| key * 9).count();
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
 
 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();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
+LL |     let _ = map.iter().map(|(_key, value)| value * 17).count();
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
 
 error: aborting due to 24 previous errors