]> git.lizzy.rs Git - rust.git/blob - tests/ui/unop-move-semantics.rs
Rollup merge of #105784 - yanns:update_stdarch, r=Amanieu
[rust.git] / tests / ui / unop-move-semantics.rs
1 // Test that move restrictions are enforced on overloaded unary operations
2
3 use std::ops::Not;
4
5 fn move_then_borrow<T: Not<Output=T> + Clone>(x: T) {
6     !x;
7
8     x.clone();  //~ ERROR: borrow of moved value
9 }
10
11 fn move_borrowed<T: Not<Output=T>>(x: T, mut y: T) {
12     let m = &x;
13     let n = &mut y;
14
15     !x;  //~ ERROR: cannot move out of `x` because it is borrowed
16
17     !y;  //~ ERROR: cannot move out of `y` because it is borrowed
18     use_mut(n); use_imm(m);
19 }
20 fn illegal_dereference<T: Not<Output=T>>(mut x: T, y: T) {
21     let m = &mut x;
22     let n = &y;
23
24     !*m;  //~ ERROR: cannot move out of `*m`
25
26     !*n;  //~ ERROR: cannot move out of `*n`
27     use_imm(n); use_mut(m);
28 }
29 fn main() {}
30
31 fn use_mut<T>(_: &mut T) { }
32 fn use_imm<T>(_: &T) { }