We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
LinkedList::detach_all_nodes
1 parent b99038f commit ffc43b8Copy full SHA for ffc43b8
library/alloc/src/collections/linked_list.rs
@@ -300,6 +300,9 @@ impl<T> LinkedList<T> {
300
let tail = self.tail.take();
301
let len = mem::replace(&mut self.len, 0);
302
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.
306
let tail = unsafe { tail.unwrap_unchecked() };
307
Some((head, tail, len))
308
} else {
0 commit comments