From d43e64dcaf055b6e5d44c9c7d0c2a126aefa0f93 Mon Sep 17 00:00:00 2001 From: Kinto Date: Mon, 17 Jun 2024 21:16:14 +0200 Subject: [PATCH] Resolve TODOs awaiting MSRV >1.62 --- src/adaptors/mod.rs | 7 ++----- src/combinations_with_replacement.rs | 6 +----- src/concat_impl.rs | 7 ++----- src/kmerge_impl.rs | 8 +++----- tests/quick.rs | 3 +-- 5 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/adaptors/mod.rs b/src/adaptors/mod.rs index 095b08918..d717e5408 100644 --- a/src/adaptors/mod.rs +++ b/src/adaptors/mod.rs @@ -1108,9 +1108,7 @@ where fn next(&mut self) -> Option { let f = &mut self.f; - // TODO: once MSRV >= 1.62, use `then_some`. - self.iter - .find_map(|(count, val)| if f(val) { Some(count) } else { None }) + self.iter.find_map(|(count, val)| f(val).then_some(count)) } fn size_hint(&self) -> (usize, Option) { @@ -1138,11 +1136,10 @@ where { fn next_back(&mut self) -> Option { let f = &mut self.f; - // TODO: once MSRV >= 1.62, use `then_some`. self.iter .by_ref() .rev() - .find_map(|(count, val)| if f(val) { Some(count) } else { None }) + .find_map(|(count, val)| f(val).then_some(count)) } fn rfold(self, init: B, mut func: G) -> B diff --git a/src/combinations_with_replacement.rs b/src/combinations_with_replacement.rs index f363f9ba2..c17e75250 100644 --- a/src/combinations_with_replacement.rs +++ b/src/combinations_with_replacement.rs @@ -73,11 +73,7 @@ where Some((increment_from, increment_value)) => { // We need to update the rightmost non-max value // and all those to the right - for i in &mut self.indices[increment_from..] { - *i = increment_value; - } - // TODO: once MSRV >= 1.50, use `fill` instead: - // self.indices[increment_from..].fill(increment_value); + self.indices[increment_from..].fill(increment_value); false } // Otherwise, we're done diff --git a/src/concat_impl.rs b/src/concat_impl.rs index ec7b91c60..d13a2931d 100644 --- a/src/concat_impl.rs +++ b/src/concat_impl.rs @@ -1,8 +1,6 @@ -use crate::Itertools; - /// Combine all an iterator's elements into one element by using [`Extend`]. /// -/// [`IntoIterator`]-enabled version of [`Itertools::concat`]. +/// [`IntoIterator`]-enabled version of [`crate::Itertools::concat`]. /// /// This combinator will extend the first item with each of the rest of the /// items of the iterator. If the iterator is empty, the default value of @@ -19,10 +17,9 @@ where I: IntoIterator, I::Item: Extend<<::Item as IntoIterator>::Item> + IntoIterator + Default, { - #[allow(deprecated)] //TODO: once msrv hits 1.51. replace `fold1` with `reduce` iterable .into_iter() - .fold1(|mut a, b| { + .reduce(|mut a, b| { a.extend(b); a }) diff --git a/src/kmerge_impl.rs b/src/kmerge_impl.rs index 0be3840a1..698c75a6d 100644 --- a/src/kmerge_impl.rs +++ b/src/kmerge_impl.rs @@ -1,5 +1,4 @@ use crate::size_hint; -use crate::Itertools; use alloc::vec::Vec; use std::fmt; @@ -128,7 +127,7 @@ impl bool> KMergePredicate for F { /// Create an iterator that merges elements of the contained iterators using /// the ordering function. /// -/// [`IntoIterator`] enabled version of [`Itertools::kmerge`]. +/// [`IntoIterator`] enabled version of [`crate::Itertools::kmerge`]. /// /// ``` /// use itertools::kmerge; @@ -172,7 +171,7 @@ where /// Create an iterator that merges elements of the contained iterators. /// -/// [`IntoIterator`] enabled version of [`Itertools::kmerge_by`]. +/// [`IntoIterator`] enabled version of [`crate::Itertools::kmerge_by`]. pub fn kmerge_by( iterable: I, mut less_than: F, @@ -223,11 +222,10 @@ where } fn size_hint(&self) -> (usize, Option) { - #[allow(deprecated)] //TODO: once msrv hits 1.51. replace `fold1` with `reduce` self.heap .iter() .map(|i| i.size_hint()) - .fold1(size_hint::add) + .reduce(size_hint::add) .unwrap_or((0, Some(0))) } } diff --git a/tests/quick.rs b/tests/quick.rs index 6fe6f6923..12b6b9d5a 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -1511,13 +1511,12 @@ quickcheck! { acc + val }); - // TODO: Swap `fold1` with stdlib's `reduce` when it's stabilized let group_map_lookup = a.iter() .map(|&b| b as u64) .map(|i| (i % modulo, i)) .into_group_map() .into_iter() - .map(|(key, vals)| (key, vals.into_iter().fold1(|acc, val| acc + val).unwrap())) + .map(|(key, vals)| (key, vals.into_iter().reduce(|acc, val| acc + val).unwrap())) .collect::>(); assert_eq!(lookup, group_map_lookup);