From ffc43b84682b9378a03b4cf5b166b2049625f7a4 Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Tue, 31 Aug 2021 11:18:30 -0400 Subject: add safety annotation to `LinkedList::detach_all_nodes` Co-authored-by: kennytm --- library/alloc/src/collections/linked_list.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'library/alloc/src') 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 LinkedList { 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 { -- cgit 1.4.1-3-g733a5