rust/tests/ui/moves/move-1-unique.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
552 B
Rust
Raw Normal View History

// run-pass
#![allow(unused_mut)]
#![allow(dead_code)]
#[derive(Clone)]
2013-07-02 19:47:32 +00:00
struct Triple {
x: isize,
y: isize,
z: isize,
2013-07-02 19:47:32 +00:00
}
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}); }
2012-08-02 00:30:05 +00:00
return y.y;
}
pub fn main() {
let x: Box<_> = Box::new(Triple{x: 1, y: 2, z: 3});
2013-07-02 19:47:32 +00:00
assert_eq!(test(true, x.clone()), 2);
assert_eq!(test(true, x.clone()), 2);
assert_eq!(test(true, x.clone()), 2);
assert_eq!(test(false, x), 5);
}