fix iter_kv_map dont suggest into_keys and into_values if msrv is to low

This commit is contained in:
Matthias Richter 2023-11-03 23:23:59 +01:00
parent d487579efd
commit 5f651da2de
6 changed files with 154 additions and 2 deletions

View file

@ -89,3 +89,46 @@ fn main() {
// Don't let a mut interfere.
let _ = map.clone().into_values().count();
}
#[clippy::msrv = "1.53"]
fn msrv_1_53() {
let map: HashMap<u32, u32> = HashMap::new();
// Don't lint because into_iter is not supported
let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>();
let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
// Lint
let _ = map.keys().collect::<Vec<_>>();
//~^ ERROR: iterating on a map's keys
let _ = map.values().collect::<Vec<_>>();
//~^ ERROR: iterating on a map's values
let _ = map.values().map(|v| v + 2).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's values
}
#[clippy::msrv = "1.54"]
fn msrv_1_54() {
// Lint all
let map: HashMap<u32, u32> = HashMap::new();
let _ = map.clone().into_keys().collect::<Vec<_>>();
//~^ ERROR: iterating on a map's keys
let _ = map.clone().into_keys().map(|key| key + 2).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's keys
let _ = map.clone().into_values().collect::<Vec<_>>();
//~^ ERROR: iterating on a map's values
let _ = map.clone().into_values().map(|val| val + 2).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's values
let _ = map.keys().collect::<Vec<_>>();
//~^ ERROR: iterating on a map's keys
let _ = map.values().collect::<Vec<_>>();
//~^ ERROR: iterating on a map's values
let _ = map.values().map(|v| v + 2).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's values
}

View file

@ -93,3 +93,46 @@ fn main() {
// Don't let a mut interfere.
let _ = map.clone().into_iter().map(|(_, mut val)| val).count();
}
#[clippy::msrv = "1.53"]
fn msrv_1_53() {
let map: HashMap<u32, u32> = HashMap::new();
// Don't lint because into_iter is not supported
let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>();
let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
// Lint
let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's keys
let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's values
let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's values
}
#[clippy::msrv = "1.54"]
fn msrv_1_54() {
// Lint all
let map: HashMap<u32, u32> = HashMap::new();
let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's keys
let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's keys
let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's values
let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's values
let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's keys
let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's values
let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
//~^ ERROR: iterating on a map's values
}

View file

@ -201,5 +201,65 @@ error: iterating on a map's values
LL | let _ = map.clone().into_iter().map(|(_, mut val)| val).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()`
error: aborting due to 28 previous errors
error: iterating on a map's keys
--> $DIR/iter_kv_map.rs:109: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:111: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:113: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 keys
--> $DIR/iter_kv_map.rs:122: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:124: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:127: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:129: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 keys
--> $DIR/iter_kv_map.rs:132: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:134: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:136:13
|
LL | let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)`
error: aborting due to 38 previous errors