1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Tests that references to move-by-default values trigger moves when
12 // they occur as part of various kinds of expressions.
14 #![feature(managed_boxes)]
16 struct Foo<A> { f: A }
17 fn guard(_s: ~str) -> bool {fail!()}
18 fn touch<A>(_a: &A) {}
21 let x = "hi".to_owned();
23 touch(&x); //~ ERROR use of moved value: `x`
27 let x = "hi".to_owned();
29 touch(&x); //~ ERROR use of moved value: `x`
33 let x = vec!(1, 2, 3);
34 let _y = (*x.get(0), 3);
39 let x = "hi".to_owned();
40 let y = "ho".to_owned();
46 touch(&x); //~ ERROR use of moved value: `x`
47 touch(&y); //~ ERROR use of moved value: `y`
51 let x = "hi".to_owned();
52 let y = "ho".to_owned();
57 touch(&x); //~ ERROR use of moved value: `x`
58 touch(&y); //~ ERROR use of moved value: `y`
62 let x = "hi".to_owned();
63 let y = "ho".to_owned();
69 touch(&x); //~ ERROR use of moved value: `x`
74 let x = "hi".to_owned();
76 touch(&x); //~ ERROR use of moved value: `x`
80 let x = "hi".to_owned();
82 touch(&x); //~ ERROR use of moved value: `x`
86 let x = vec!("hi".to_owned());
87 let _y = x.move_iter().next().unwrap();
88 touch(&x); //~ ERROR use of moved value: `x`
92 let x = vec!("hi".to_owned());
93 let _y = [x.move_iter().next().unwrap(), ..1];
94 touch(&x); //~ ERROR use of moved value: `x`
98 let mut x = vec!("hi".to_owned(), "ho".to_owned());
99 x.as_mut_slice().swap(0, 1);