diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2021-09-02 19:10:14 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-02 19:10:14 +0200 |
| commit | 8fd1bf332350b5899f040d749fa2bcc21ac4e23e (patch) | |
| tree | f45961ad80e16fdb8740481bf1969c27355bfdd6 /library/alloc/src/collections | |
| parent | e50069ff4f4b8c95443103d747f6aa22e64dc22c (diff) | |
| parent | ffc43b84682b9378a03b4cf5b166b2049625f7a4 (diff) | |
| download | rust-8fd1bf332350b5899f040d749fa2bcc21ac4e23e.tar.gz rust-8fd1bf332350b5899f040d749fa2bcc21ac4e23e.zip | |
Rollup merge of #88505 - ibraheemdev:use-unwrap-unchecked, r=kennytm
Use `unwrap_unchecked` where possible
Diffstat (limited to 'library/alloc/src/collections')
| -rw-r--r-- | library/alloc/src/collections/linked_list.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index 7aa24ff4afa..9d45c5082db 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -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 |
