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 // Test that move restrictions are enforced on overloaded binary operations
15 fn double_move<T: Add<Output=()>>(x: T) {
18 x; //~ ERROR: use of moved value
21 fn move_then_borrow<T: Add<Output=()> + Clone>(x: T) {
24 x.clone(); //~ ERROR: use of moved value
27 fn move_borrowed<T: Add<Output=()>>(x: T, mut y: T) {
31 x //~ ERROR: cannot move out of `x` because it is borrowed
33 y; //~ ERROR: cannot move out of `y` because it is borrowed
36 fn illegal_dereference<T: Add<Output=()>>(mut x: T, y: T) {
40 *m //~ ERROR: cannot move out of borrowed content
42 *n; //~ ERROR: cannot move out of borrowed content
47 impl<'a, 'b> Add<&'b Foo> for &'a mut Foo {
50 fn add(self, _: &Foo) {}
53 impl<'a, 'b> Add<&'b mut Foo> for &'a Foo {
56 fn add(self, _: &mut Foo) {}
64 &f; //~ ERROR: cannot borrow `f` as immutable because it is also borrowed as mutable
65 //~^ cannot borrow `f` as immutable because it is also borrowed as mutable
73 &mut f; //~ ERROR: cannot borrow `f` as mutable because it is also borrowed as immutable
74 //~^ cannot borrow `f` as mutable because it is also borrowed as immutable