From 807066f8c9cacf1f8acf3a7be25c14cc46d99f58 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Fri, 28 Nov 2014 13:20:37 +0100 Subject: [PATCH] Add test for #18908 --- src/libcollections/vec.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 5edd3d0b780be..d3ebf74fa8a0b 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -2108,6 +2108,35 @@ mod tests { assert_eq!(v.map_in_place(|_| ZeroSized).as_slice(), [ZeroSized, ZeroSized].as_slice()); } + #[test] + fn test_map_in_place_zero_drop_count() { + use std::sync::atomic; + use std::sync::atomic::AtomicUint; + + #[deriving(Clone, PartialEq, Show)] + struct Nothing; + impl Drop for Nothing { fn drop(&mut self) { } } + + #[deriving(Clone, PartialEq, Show)] + struct ZeroSized; + impl Drop for ZeroSized { + fn drop(&mut self) { + DROP_COUNTER.fetch_add(1, atomic::Relaxed); + } + } + const NUM_ELEMENTS: uint = 2; + static DROP_COUNTER: AtomicUint = atomic::INIT_ATOMIC_UINT; + + let v = Vec::from_elem(NUM_ELEMENTS, Nothing); + + DROP_COUNTER.store(0, atomic::Relaxed); + + let v = v.map_in_place(|_| ZeroSized); + assert_eq!(DROP_COUNTER.load(atomic::Relaxed), 0); + drop(v); + assert_eq!(DROP_COUNTER.load(atomic::Relaxed), NUM_ELEMENTS); + } + #[test] fn test_move_items() { let vec = vec![1, 2, 3];