add safety annotation to LinkedList::detach_all_nodes

Co-authored-by: kennytm <kennytm@gmail.com>
This commit is contained in:
Ibraheem Ahmed 2021-08-31 11:18:30 -04:00 committed by GitHub
parent b99038f478
commit ffc43b8468
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {