From 19e98d0e01581048a8bdab3993e13719dd1cdbc0 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 24 Apr 2024 13:53:35 -0700 Subject: [PATCH] Rename `UnindexedRangeLen::len` to `unindexed_len` This avoids potential ambiguity in case the standard library ever expands `ExactSizeIterator` to more ranges. (cherry picked from commit 1f399d006680dba1911425d55f8a74b128429b7e) --- src/range.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/range.rs b/src/range.rs index 57b613e1c..6af8d630c 100644 --- a/src/range.rs +++ b/src/range.rs @@ -213,13 +213,13 @@ macro_rules! indexed_range_impl { } trait UnindexedRangeLen { - fn len(&self) -> L; + fn unindexed_len(&self) -> L; } macro_rules! unindexed_range_impl { ( $t:ty, $len_t:ty ) => { impl UnindexedRangeLen<$len_t> for Range<$t> { - fn len(&self) -> $len_t { + fn unindexed_len(&self) -> $len_t { let &Range { start, end } = self; if end > start { end.wrapping_sub(start) as $len_t @@ -253,7 +253,7 @@ macro_rules! unindexed_range_impl { } fn opt_len(iter: &Iter<$t>) -> Option { - usize::try_from(iter.range.len()).ok() + usize::try_from(iter.range.unindexed_len()).ok() } } @@ -261,7 +261,7 @@ macro_rules! unindexed_range_impl { type Item = $t; fn split(mut self) -> (Self, Option) { - let index = self.range.len() / 2; + let index = self.range.unindexed_len() / 2; if index > 0 { let mid = self.range.start.wrapping_add(index as $t); let right = mid..self.range.end; @@ -387,11 +387,14 @@ fn test_i128_len_doesnt_overflow() { range: 0..octillion, }; - assert_eq!(octillion as u128, producer.range.len()); - assert_eq!(octillion as u128, (0..octillion).len()); - assert_eq!(2 * octillion as u128, (-octillion..octillion).len()); + assert_eq!(octillion as u128, producer.range.unindexed_len()); + assert_eq!(octillion as u128, (0..octillion).unindexed_len()); + assert_eq!( + 2 * octillion as u128, + (-octillion..octillion).unindexed_len() + ); - assert_eq!(u128::MAX, (i128::MIN..i128::MAX).len()); + assert_eq!(u128::MAX, (i128::MIN..i128::MAX).unindexed_len()); } #[test]