Skip to content

Commit 807066f

Browse files
committedNov 28, 2014
Add test for #18908
1 parent fb52e69 commit 807066f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
 

‎src/libcollections/vec.rs

+29
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,35 @@ mod tests {
21082108
assert_eq!(v.map_in_place(|_| ZeroSized).as_slice(), [ZeroSized, ZeroSized].as_slice());
21092109
}
21102110

2111+
#[test]
2112+
fn test_map_in_place_zero_drop_count() {
2113+
use std::sync::atomic;
2114+
use std::sync::atomic::AtomicUint;
2115+
2116+
#[deriving(Clone, PartialEq, Show)]
2117+
struct Nothing;
2118+
impl Drop for Nothing { fn drop(&mut self) { } }
2119+
2120+
#[deriving(Clone, PartialEq, Show)]
2121+
struct ZeroSized;
2122+
impl Drop for ZeroSized {
2123+
fn drop(&mut self) {
2124+
DROP_COUNTER.fetch_add(1, atomic::Relaxed);
2125+
}
2126+
}
2127+
const NUM_ELEMENTS: uint = 2;
2128+
static DROP_COUNTER: AtomicUint = atomic::INIT_ATOMIC_UINT;
2129+
2130+
let v = Vec::from_elem(NUM_ELEMENTS, Nothing);
2131+
2132+
DROP_COUNTER.store(0, atomic::Relaxed);
2133+
2134+
let v = v.map_in_place(|_| ZeroSized);
2135+
assert_eq!(DROP_COUNTER.load(atomic::Relaxed), 0);
2136+
drop(v);
2137+
assert_eq!(DROP_COUNTER.load(atomic::Relaxed), NUM_ELEMENTS);
2138+
}
2139+
21112140
#[test]
21122141
fn test_move_items() {
21132142
let vec = vec![1, 2, 3];

0 commit comments

Comments
 (0)