about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass/address-reuse.rs
blob: 9b5c8c38b8fba714edca0e8a3d8508c793b963dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! Check that we do sometimes reuse addresses.
use std::collections::HashSet;

fn main() {
    let count = 100;
    let mut addrs = HashSet::<usize>::new();
    for _ in 0..count {
        // We make a `Box` with a layout that's hopefully not used by tons of things inside the
        // allocator itself, so that we are more likely to get reuse. (With `i32` or `usize`, on
        // Windows the reuse chances are very low.)
        let b = Box::new([42usize; 4]);
        addrs.insert(&*b as *const [usize; 4] as usize);
    }
    // dbg!(addrs.len());
    assert!(addrs.len() > 1 && addrs.len() < count);
}