See the following code:
pub struct ListNode {
next: Option<Box<ListNode>>
}
pub fn foo(mut head: Box<ListNode>) -> Box<ListNode> {
let mut cur = &mut head;
while let Some(next) = std::mem::replace(&mut cur.next, None) {
cur.next = Some(next);
cur = cur.next.as_mut().unwrap();
}
head
}
Apparently the unwrap should never panic given the assignment in the previous line. However, based on the assembly output, that check isn't optimized away.
(The while let statement seems to be generating useless function calls for drop as well, btw.)
See the following code:
Apparently the
unwrapshould never panic given the assignment in the previous line. However, based on the assembly output, that check isn't optimized away.(The
while letstatement seems to be generating useless function calls for drop as well, btw.)