mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-27 07:03:45 +00:00
add safety annotation to LinkedList::detach_all_nodes
Co-authored-by: kennytm <kennytm@gmail.com>
This commit is contained in:
parent
b99038f478
commit
ffc43b8468
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user