summaryrefslogtreecommitdiffstats
path: root/tests/ui/moves/move-3-unique.rs
blob: 8e5df2c3ff9fd6e93a155707545df7e77608f091 (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
// run-pass
#![allow(unused_mut)]
#![allow(dead_code)]

#[derive(Clone)]
struct Triple {
    x: isize,
    y: isize,
    z: isize,
}

fn test(x: bool, foo: Box<Triple>) -> isize {
    let bar = foo;
    let mut y: Box<Triple>;
    if x { y = bar; } else { y = Box::new(Triple {x: 4, y: 5, z: 6}); }
    return y.y;
}

pub fn main() {
    let x: Box<_> = Box::new(Triple{x: 1, y: 2, z: 3});
    for _ in 0_usize..10000_usize {
        assert_eq!(test(true, x.clone()), 2);
    }
    assert_eq!(test(false, x), 5);
}