diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:12:43 +0000 |
commit | cf94bdc0742c13e2a0cac864c478b8626b266e1b (patch) | |
tree | 044670aa50cc5e2b4229aa0b6b3df6676730c0a6 /src/tools/clippy/tests/ui/iter_kv_map.fixed | |
parent | Adding debian version 1.65.0+dfsg1-2. (diff) | |
download | rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.tar.xz rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.zip |
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/iter_kv_map.fixed')
-rw-r--r-- | src/tools/clippy/tests/ui/iter_kv_map.fixed | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/iter_kv_map.fixed b/src/tools/clippy/tests/ui/iter_kv_map.fixed new file mode 100644 index 000000000..83fee0408 --- /dev/null +++ b/src/tools/clippy/tests/ui/iter_kv_map.fixed @@ -0,0 +1,64 @@ +// 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(); +} |