Skip to content

Commit dea7143

Browse files
committed
auto merge of #19377 : tbu-/rust/pr_mapinplace_fixzerosized_test, r=sfackler
2 parents 872ba2c + 807066f commit dea7143

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
@@ -2160,6 +2160,35 @@ mod tests {
21602160
assert_eq!(v.map_in_place(|_| ZeroSized), [ZeroSized, ZeroSized]);
21612161
}
21622162

2163+
#[test]
2164+
fn test_map_in_place_zero_drop_count() {
2165+
use std::sync::atomic;
2166+
use std::sync::atomic::AtomicUint;
2167+
2168+
#[deriving(Clone, PartialEq, Show)]
2169+
struct Nothing;
2170+
impl Drop for Nothing { fn drop(&mut self) { } }
2171+
2172+
#[deriving(Clone, PartialEq, Show)]
2173+
struct ZeroSized;
2174+
impl Drop for ZeroSized {
2175+
fn drop(&mut self) {
2176+
DROP_COUNTER.fetch_add(1, atomic::Relaxed);
2177+
}
2178+
}
2179+
const NUM_ELEMENTS: uint = 2;
2180+
static DROP_COUNTER: AtomicUint = atomic::INIT_ATOMIC_UINT;
2181+
2182+
let v = Vec::from_elem(NUM_ELEMENTS, Nothing);
2183+
2184+
DROP_COUNTER.store(0, atomic::Relaxed);
2185+
2186+
let v = v.map_in_place(|_| ZeroSized);
2187+
assert_eq!(DROP_COUNTER.load(atomic::Relaxed), 0);
2188+
drop(v);
2189+
assert_eq!(DROP_COUNTER.load(atomic::Relaxed), NUM_ELEMENTS);
2190+
}
2191+
21632192
#[test]
21642193
fn test_move_items() {
21652194
let vec = vec![1, 2, 3];

0 commit comments

Comments
 (0)