Skip to content

Commit ffc43b8

Browse files
ibraheemdevkennytm
andauthored
add safety annotation to LinkedList::detach_all_nodes
Co-authored-by: kennytm <[email protected]>
1 parent b99038f commit ffc43b8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

library/alloc/src/collections/linked_list.rs

+3
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ impl<T> LinkedList<T> {
300300
let tail = self.tail.take();
301301
let len = mem::replace(&mut self.len, 0);
302302
if let Some(head) = head {
303+
// SAFETY: In a LinkedList, either both the head and tail are None because
304+
// the list is empty, or both head and tail are Some because the list is populated.
305+
// Since we have verified the head is Some, we are sure the tail is Some too.
303306
let tail = unsafe { tail.unwrap_unchecked() };
304307
Some((head, tail, len))
305308
} else {

0 commit comments

Comments
 (0)