]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/unop-move-semantics.rs
New upstream version 1.24.1+dfsg1
[rustc.git] / src / test / compile-fail / unop-move-semantics.rs
CommitLineData
1a4d82fc
JJ
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.
4//
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.
10
11// Test that move restrictions are enforced on overloaded unary operations
12
13use std::ops::Not;
14
15fn move_then_borrow<T: Not<Output=T> + Clone>(x: T) {
16 !x;
17
18 x.clone(); //~ ERROR: use of moved value
19}
20
21fn move_borrowed<T: Not<Output=T>>(x: T, mut y: T) {
22 let m = &x;
23 let n = &mut y;
24
25 !x; //~ ERROR: cannot move out of `x` because it is borrowed
26
27 !y; //~ ERROR: cannot move out of `y` because it is borrowed
28}
29
30fn illegal_dereference<T: Not<Output=T>>(mut x: T, y: T) {
31 let m = &mut x;
32 let n = &y;
33
34 !*m; //~ ERROR: cannot move out of borrowed content
35
36 !*n; //~ ERROR: cannot move out of borrowed content
37}
38
39fn main() {}