#drop #check #tooling #correctness #token #set

dropcheck

Tooling to check the correctness of Drop implementations

2 releases

0.1.1 Dec 29, 2019
0.1.0 Dec 29, 2019

#700 in Testing

22 downloads per month
Used in 3 crates

MIT/Apache

9KB
111 lines

dropcheck

Tooling to check the correctness of Drop implementations.


lib.rs:

Tooling to check the correctness of Drop implementations.

Properly testing a container type like Vec<T> requires verifying that every value in the container is neither leaked, nor dropped multiple times.

To detect leaks, this crate provides a DropToken type whose drop implementation sets a flag in a DropState with interior mutability (specifically atomics). Secondly, these states are stored in a DropCheck set. If any any token hasn't been dropped when the DropCheck is dropped, the DropCheck's drop impl panics:

let dropcheck = DropCheck::new();
let token = dropcheck.token();

std::mem::forget(token); // leaked!
// panics when dropcheck goes out of scope

Secondly, dropping a token twice panics:

let dropcheck = DropCheck::new();
let mut token = dropcheck.token();

unsafe {
    std::ptr::drop_in_place(&mut token);
    std::ptr::drop_in_place(&mut token); // panics
}

No runtime deps