diff options
| author | Ibraheem Ahmed <ibrah1440@gmail.com> | 2021-08-31 11:18:30 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-31 11:18:30 -0400 |
| commit | ffc43b84682b9378a03b4cf5b166b2049625f7a4 (patch) | |
| tree | 131804c892a9846f68397c394e89fb597098a3d1 | |
| parent | b99038f4780d918224cd1aed6da2f9d6b42e7481 (diff) | |
| download | rust-ffc43b84682b9378a03b4cf5b166b2049625f7a4.tar.gz rust-ffc43b84682b9378a03b4cf5b166b2049625f7a4.zip | |
add safety annotation to `LinkedList::detach_all_nodes`
Co-authored-by: kennytm <kennytm@gmail.com>
| -rw-r--r-- | library/alloc/src/collections/linked_list.rs | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index 77f09a2377a..9d45c5082db 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -300,6 +300,9 @@ impl<T> LinkedList<T> { let tail = self.tail.take(); let len = mem::replace(&mut self.len, 0); if let Some(head) = head { + // 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 { |
