Skip to content

Commit

Permalink
auto merge of rust-lang#19377 : tbu-/rust/pr_mapinplace_fixzerosized_…
Browse files Browse the repository at this point in the history
…test, r=sfackler
  • Loading branch information
bors committed Dec 11, 2014
2 parents 872ba2c + 807066f commit dea7143
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 @@ -2160,6 +2160,35 @@ mod tests {
assert_eq!(v.map_in_place(|_| ZeroSized), [ZeroSized, ZeroSized]);
}

#[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 dea7143

Please sign in to comment.