X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fliballoc%2Fcollections%2Fbtree%2Fmap.rs;h=b1f0ef0085f2d42a91f4145302ff788c7aea8358;hb=892cb143e5984f220e6b26b48d972bd1f4644298;hp=74069bbf8a3e5a271cbc15949ec46705d13e9365;hpb=0860f5aebd1939b821cf9af5ba568cbd6be8077e;p=rust.git diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs index 74069bbf8a3..b1f0ef0085f 100644 --- a/src/liballoc/collections/btree/map.rs +++ b/src/liballoc/collections/btree/map.rs @@ -1470,7 +1470,22 @@ fn into_iter(self) -> IntoIter { #[stable(feature = "btree_drop", since = "1.7.0")] impl Drop for IntoIter { fn drop(&mut self) { - self.for_each(drop); + struct DropGuard<'a, K, V>(&'a mut IntoIter); + + impl<'a, K, V> Drop for DropGuard<'a, K, V> { + fn drop(&mut self) { + // Continue the same loop we perform below. This only runs when unwinding, so we + // don't have to care about panics this time (they'll abort). + while let Some(_) = self.0.next() {} + } + } + + while let Some(pair) = self.next() { + let guard = DropGuard(self); + drop(pair); + mem::forget(guard); + } + unsafe { let leaf_node = ptr::read(&self.front).into_node(); if leaf_node.is_shared_root() {