Simplify drop test (Rc is redundant)

This commit is contained in:
root
2015-05-21 15:45:16 +02:00
parent 14550015d9
commit 00466e6efd
2 changed files with 17 additions and 19 deletions
+8 -9
View File
@@ -93,14 +93,13 @@ fn test_no_nonnullable_opt() {
#[test] #[test]
fn test_drop() { fn test_drop() {
use std::rc::Rc;
use std::cell::Cell; use std::cell::Cell;
let flag = Rc::new(Cell::new(0)); let flag = &Cell::new(0);
struct Foo(Rc<Cell<i32>>); struct Bump<'a>(&'a Cell<i32>);
impl Drop for Foo { impl<'a> Drop for Bump<'a> {
fn drop(&mut self) { fn drop(&mut self) {
let n = self.0.get(); let n = self.0.get();
self.0.set(n + 1); self.0.set(n + 1);
@@ -108,7 +107,7 @@ fn test_drop() {
} }
{ {
let _ = NoDrop::new([Foo(flag.clone()), Foo(flag.clone())]); let _ = NoDrop::new([Bump(flag), Bump(flag)]);
} }
assert_eq!(flag.get(), 0); assert_eq!(flag.get(), 0);
@@ -117,10 +116,10 @@ fn test_drop() {
{ {
let mut array = NoDrop::new(Vec::new()); let mut array = NoDrop::new(Vec::new());
array.push(vec![Foo(flag.clone())]); array.push(vec![Bump(flag)]);
array.push(vec![Foo(flag.clone()), Foo(flag.clone())]); array.push(vec![Bump(flag), Bump(flag)]);
array.push(vec![]); array.push(vec![]);
array.push(vec![Foo(flag.clone())]); array.push(vec![Bump(flag)]);
drop(array.pop()); drop(array.pop());
assert_eq!(flag.get(), 1); assert_eq!(flag.get(), 1);
drop(array.pop()); drop(array.pop());
@@ -134,7 +133,7 @@ fn test_drop() {
flag.set(0); flag.set(0);
{ {
let mut array = NoDrop::new(Foo(flag.clone())); let array = NoDrop::new(Bump(flag));
array.into_inner(); array.into_inner();
assert_eq!(flag.get(), 1); assert_eq!(flag.get(), 1);
} }
+9 -10
View File
@@ -449,14 +449,13 @@ fn test_iter() {
#[test] #[test]
fn test_drop() { fn test_drop() {
use std::rc::Rc;
use std::cell::Cell; use std::cell::Cell;
let flag = Rc::new(Cell::new(0)); let flag = &Cell::new(0);
struct Foo(Rc<Cell<i32>>); struct Bump<'a>(&'a Cell<i32>);
impl Drop for Foo { impl<'a> Drop for Bump<'a> {
fn drop(&mut self) { fn drop(&mut self) {
let n = self.0.get(); let n = self.0.get();
self.0.set(n + 1); self.0.set(n + 1);
@@ -464,9 +463,9 @@ fn test_drop() {
} }
{ {
let mut array = ArrayVec::<[Foo; 128]>::new(); let mut array = ArrayVec::<[Bump; 128]>::new();
array.push(Foo(flag.clone())); array.push(Bump(flag));
array.push(Foo(flag.clone())); array.push(Bump(flag));
} }
assert_eq!(flag.get(), 2); assert_eq!(flag.get(), 2);
@@ -475,10 +474,10 @@ fn test_drop() {
{ {
let mut array = ArrayVec::<[_; 3]>::new(); let mut array = ArrayVec::<[_; 3]>::new();
array.push(vec![Foo(flag.clone())]); array.push(vec![Bump(flag)]);
array.push(vec![Foo(flag.clone()), Foo(flag.clone())]); array.push(vec![Bump(flag), Bump(flag)]);
array.push(vec![]); array.push(vec![]);
array.push(vec![Foo(flag.clone())]); array.push(vec![Bump(flag)]);
assert_eq!(flag.get(), 1); assert_eq!(flag.get(), 1);
drop(array.pop()); drop(array.pop());
assert_eq!(flag.get(), 1); assert_eq!(flag.get(), 1);