mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Rollup merge of #88505 - ibraheemdev:use-unwrap-unchecked, r=kennytm
Use `unwrap_unchecked` where possible
This commit is contained in:
commit
8fd1bf3323
@ -300,7 +300,10 @@ impl<T> LinkedList<T> {
|
||||
let tail = self.tail.take();
|
||||
let len = mem::replace(&mut self.len, 0);
|
||||
if let Some(head) = head {
|
||||
let tail = tail.unwrap_or_else(|| unsafe { core::hint::unreachable_unchecked() });
|
||||
// SAFETY: In a LinkedList, either both the head and tail are None because
|
||||
// the list is empty, or both head and tail are Some because the list is populated.
|
||||
// Since we have verified the head is Some, we are sure the tail is Some too.
|
||||
let tail = unsafe { tail.unwrap_unchecked() };
|
||||
Some((head, tail, len))
|
||||
} else {
|
||||
None
|
||||
|
@ -459,11 +459,8 @@ where
|
||||
debug_assert!(N <= iter.size_hint().1.unwrap_or(usize::MAX));
|
||||
debug_assert!(N <= iter.size_hint().0);
|
||||
|
||||
match collect_into_array(iter) {
|
||||
Some(array) => array,
|
||||
// SAFETY: covered by the function contract.
|
||||
None => unsafe { crate::hint::unreachable_unchecked() },
|
||||
}
|
||||
// SAFETY: covered by the function contract.
|
||||
unsafe { collect_into_array(iter).unwrap_unchecked() }
|
||||
}
|
||||
|
||||
/// Pulls `N` items from `iter` and returns them as an array. If the iterator
|
||||
|
@ -1198,11 +1198,8 @@ impl<T> Option<T> {
|
||||
pub fn insert(&mut self, value: T) -> &mut T {
|
||||
*self = Some(value);
|
||||
|
||||
match self {
|
||||
Some(v) => v,
|
||||
// SAFETY: the code above just filled the option
|
||||
None => unsafe { hint::unreachable_unchecked() },
|
||||
}
|
||||
// SAFETY: the code above just filled the option
|
||||
unsafe { self.as_mut().unwrap_unchecked() }
|
||||
}
|
||||
|
||||
/// Inserts `value` into the option if it is [`None`], then
|
||||
|
Loading…
Reference in New Issue
Block a user