Skip to content

Commit

Permalink
Add test for rust-lang#18908
Browse files Browse the repository at this point in the history
  • Loading branch information
tbu- committed Nov 28, 2014
1 parent fb52e69 commit 807066f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 807066f

Please sign in to comment.