2022-08-29 18:39:25 +00:00
|
|
|
#![warn(clippy::iter_kv_map)]
|
2023-01-04 21:32:34 +00:00
|
|
|
#![allow(unused_mut, clippy::redundant_clone, clippy::suspicious_map, clippy::map_identity)]
|
2022-08-29 18:39:25 +00:00
|
|
|
|
|
|
|
use std::collections::{BTreeMap, HashMap};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let get_key = |(key, _val)| key;
|
2023-01-04 21:32:34 +00:00
|
|
|
fn ref_acceptor(v: &u32) -> u32 {
|
|
|
|
*v
|
|
|
|
}
|
2022-08-29 18:39:25 +00:00
|
|
|
|
|
|
|
let map: HashMap<u32, u32> = HashMap::new();
|
|
|
|
|
|
|
|
let _ = map.keys().collect::<Vec<_>>();
|
|
|
|
let _ = map.values().collect::<Vec<_>>();
|
|
|
|
let _ = map.values().map(|v| v + 2).collect::<Vec<_>>();
|
|
|
|
|
|
|
|
let _ = map.clone().into_keys().collect::<Vec<_>>();
|
|
|
|
let _ = map.clone().into_keys().map(|key| key + 2).collect::<Vec<_>>();
|
|
|
|
|
|
|
|
let _ = map.clone().into_values().collect::<Vec<_>>();
|
|
|
|
let _ = map.clone().into_values().map(|val| val + 2).collect::<Vec<_>>();
|
|
|
|
|
|
|
|
let _ = map.clone().values().collect::<Vec<_>>();
|
2022-09-15 04:16:01 +00:00
|
|
|
let _ = map.keys().filter(|x| *x % 2 == 0).count();
|
2022-08-29 18:39:25 +00:00
|
|
|
|
|
|
|
// Don't lint
|
2022-09-15 04:16:01 +00:00
|
|
|
let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
|
|
|
|
let _ = map.iter().map(get_key).collect::<Vec<_>>();
|
2022-08-29 18:39:25 +00:00
|
|
|
|
|
|
|
// Linting the following could be an improvement to the lint
|
|
|
|
// map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
|
|
|
|
|
|
|
|
// Lint
|
2022-09-15 04:16:01 +00:00
|
|
|
let _ = map.keys().map(|key| key * 9).count();
|
|
|
|
let _ = map.values().map(|value| value * 17).count();
|
2022-08-29 18:39:25 +00:00
|
|
|
|
2023-01-04 21:32:34 +00:00
|
|
|
// Preserve the ref in the fix.
|
|
|
|
let _ = map.clone().into_values().map(|ref val| ref_acceptor(val)).count();
|
|
|
|
|
|
|
|
// Preserve the mut in the fix.
|
|
|
|
let _ = map
|
|
|
|
.clone().into_values().map(|mut val| {
|
|
|
|
val += 2;
|
|
|
|
val
|
|
|
|
})
|
|
|
|
.count();
|
|
|
|
|
|
|
|
// Don't let a mut interfere.
|
|
|
|
let _ = map.clone().into_values().count();
|
|
|
|
|
2022-08-29 18:39:25 +00:00
|
|
|
let map: BTreeMap<u32, u32> = BTreeMap::new();
|
|
|
|
|
|
|
|
let _ = map.keys().collect::<Vec<_>>();
|
|
|
|
let _ = map.values().collect::<Vec<_>>();
|
|
|
|
let _ = map.values().map(|v| v + 2).collect::<Vec<_>>();
|
|
|
|
|
|
|
|
let _ = map.clone().into_keys().collect::<Vec<_>>();
|
|
|
|
let _ = map.clone().into_keys().map(|key| key + 2).collect::<Vec<_>>();
|
|
|
|
|
|
|
|
let _ = map.clone().into_values().collect::<Vec<_>>();
|
|
|
|
let _ = map.clone().into_values().map(|val| val + 2).collect::<Vec<_>>();
|
|
|
|
|
|
|
|
let _ = map.clone().values().collect::<Vec<_>>();
|
2022-09-15 04:16:01 +00:00
|
|
|
let _ = map.keys().filter(|x| *x % 2 == 0).count();
|
2022-08-29 18:39:25 +00:00
|
|
|
|
|
|
|
// Don't lint
|
2022-09-15 04:16:01 +00:00
|
|
|
let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
|
|
|
|
let _ = map.iter().map(get_key).collect::<Vec<_>>();
|
2022-08-29 18:39:25 +00:00
|
|
|
|
|
|
|
// Linting the following could be an improvement to the lint
|
|
|
|
// map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
|
|
|
|
|
|
|
|
// Lint
|
2022-09-15 04:16:01 +00:00
|
|
|
let _ = map.keys().map(|key| key * 9).count();
|
|
|
|
let _ = map.values().map(|value| value * 17).count();
|
2023-01-04 21:32:34 +00:00
|
|
|
|
|
|
|
// Preserve the ref in the fix.
|
|
|
|
let _ = map.clone().into_values().map(|ref val| ref_acceptor(val)).count();
|
|
|
|
|
|
|
|
// Preserve the mut in the fix.
|
|
|
|
let _ = map
|
|
|
|
.clone().into_values().map(|mut val| {
|
|
|
|
val += 2;
|
|
|
|
val
|
|
|
|
})
|
|
|
|
.count();
|
|
|
|
|
|
|
|
// Don't let a mut interfere.
|
|
|
|
let _ = map.clone().into_values().count();
|
2022-08-29 18:39:25 +00:00
|
|
|
}
|