[][src]Crate dropcheck

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
}

Structs

DropCheck

A set of DropToken's.

DropState

The state of a particular DropToken.

DropToken

A drop-checking token.