mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-15 01:55:03 +00:00
65 lines
2.2 KiB
Rust
65 lines
2.2 KiB
Rust
// run-rustfix
|
|
|
|
#![warn(clippy::iter_kv_map)]
|
|
#![allow(clippy::redundant_clone)]
|
|
#![allow(clippy::suspicious_map)]
|
|
#![allow(clippy::map_identity)]
|
|
|
|
use std::collections::{BTreeMap, HashMap};
|
|
|
|
fn main() {
|
|
let get_key = |(key, _val)| key;
|
|
|
|
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<_>>();
|
|
let _ = map.keys().filter(|x| *x % 2 == 0).count();
|
|
|
|
// Don't lint
|
|
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
|
|
let _ = map.keys().map(|key| key * 9).count();
|
|
let _ = map.values().map(|value| value * 17).count();
|
|
|
|
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<_>>();
|
|
let _ = map.keys().filter(|x| *x % 2 == 0).count();
|
|
|
|
// Don't lint
|
|
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
|
|
let _ = map.keys().map(|key| key * 9).count();
|
|
let _ = map.values().map(|value| value * 17).count();
|
|
}
|