Skip to content

Commit

Permalink
Auto merge of #81956 - ssomers:btree_post_75200, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
BTree: remove outdated traces of coercions

The introduction of `marker::ValMut` (#75200) meant iterators no longer see mutable keys but their code still pretends it does. And settle on the majority style `Some(unsafe {…})` over `unsafe { Some(…) }`.

r? `@Mark-Simulacrum`
  • Loading branch information
bors committed Feb 14, 2021
2 parents 8e54a21 + f81358d commit b86674e
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() })
}
}

Expand Down Expand Up @@ -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() })
}
}
}
Expand Down Expand Up @@ -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() })
}
}

Expand Down Expand Up @@ -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() })
}
}
}
Expand Down Expand Up @@ -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)> {
Expand Down Expand Up @@ -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)> {
Expand Down Expand Up @@ -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() }) }
}
}

Expand Down

0 comments on commit b86674e

Please sign in to comment.