diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index bea83a37d531b..801615b3dc261 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -1279,7 +1279,7 @@ impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> { None } else { self.length -= 1; - unsafe { Some(self.range.next_unchecked()) } + Some(unsafe { self.range.next_unchecked() }) } } @@ -1310,7 +1310,7 @@ impl<'a, K: 'a, V: 'a> DoubleEndedIterator for Iter<'a, K, V> { None } else { self.length -= 1; - unsafe { Some(self.range.next_back_unchecked()) } + Some(unsafe { self.range.next_back_unchecked() }) } } } @@ -1348,8 +1348,7 @@ impl<'a, K: 'a, V: 'a> Iterator for IterMut<'a, K, V> { None } else { self.length -= 1; - let (k, v) = unsafe { self.range.next_unchecked() }; - Some((k, v)) // coerce k from `&mut K` to `&K` + Some(unsafe { self.range.next_unchecked() }) } } @@ -1377,8 +1376,7 @@ impl<'a, K: 'a, V: 'a> DoubleEndedIterator for IterMut<'a, K, V> { None } else { self.length -= 1; - let (k, v) = unsafe { self.range.next_back_unchecked() }; - Some((k, v)) // coerce k from `&mut K` to `&K` + Some(unsafe { self.range.next_back_unchecked() }) } } } @@ -1700,7 +1698,7 @@ impl<'a, K, V> Iterator for Range<'a, K, V> { type Item = (&'a K, &'a V); fn next(&mut self) -> Option<(&'a K, &'a V)> { - if self.is_empty() { None } else { unsafe { Some(self.next_unchecked()) } } + if self.is_empty() { None } else { Some(unsafe { self.next_unchecked() }) } } fn last(mut self) -> Option<(&'a K, &'a V)> { @@ -1864,12 +1862,7 @@ impl<'a, K, V> Iterator for RangeMut<'a, K, V> { type Item = (&'a K, &'a mut V); fn next(&mut self) -> Option<(&'a K, &'a mut V)> { - if self.is_empty() { - None - } else { - let (k, v) = unsafe { self.next_unchecked() }; - Some((k, v)) // coerce k from `&mut K` to `&K` - } + if self.is_empty() { None } else { Some(unsafe { self.next_unchecked() }) } } fn last(mut self) -> Option<(&'a K, &'a mut V)> { @@ -1907,12 +1900,7 @@ impl<'a, K, V> RangeMut<'a, K, V> { #[stable(feature = "btree_range", since = "1.17.0")] impl<'a, K, V> DoubleEndedIterator for RangeMut<'a, K, V> { fn next_back(&mut self) -> Option<(&'a K, &'a mut V)> { - if self.is_empty() { - None - } else { - let (k, v) = unsafe { self.next_back_unchecked() }; - Some((k, v)) // coerce k from `&mut K` to `&K` - } + if self.is_empty() { None } else { Some(unsafe { self.next_back_unchecked() }) } } }