about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass/tree_borrows/copy-nonoverlapping.rs
blob: 23250d6e6dfc5cb77c8de12273cbb61116d49e03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//@compile-flags: -Zmiri-tree-borrows

// copy_nonoverlapping works regardless of the order in which we construct
// the arguments.
pub fn main() {
    test_to_from();
    test_from_to();
}

fn test_to_from() {
    unsafe {
        let data = &mut [0u64, 1];
        let to = data.as_mut_ptr().add(1);
        let from = data.as_ptr();
        std::ptr::copy_nonoverlapping(from, to, 1);
    }
}

// Stacked Borrows would not have liked this one because the `as_mut_ptr` reborrow
// invalidates the earlier pointer obtained from `as_ptr`, but Tree Borrows is fine
// with it.
fn test_from_to() {
    unsafe {
        let data = &mut [0u64, 1];
        let from = data.as_ptr();
        let to = data.as_mut_ptr().add(1);
        std::ptr::copy_nonoverlapping(from, to, 1);
    }
}