]> git.proxmox.com Git - rustc.git/blob - src/test/ui/pattern/bindings-after-at/default-binding-modes-both-sides-independent.rs
New upstream version 1.43.0+dfsg1
[rustc.git] / src / test / ui / pattern / bindings-after-at / default-binding-modes-both-sides-independent.rs
1 // Ensures the independence of each side in `binding @ subpat`
2 // determine their binding modes independently of each other.
3 //
4 // That is, `binding` does not influence `subpat`.
5 // This is important because we might want to allow `p1 @ p2`,
6 // where both `p1` and `p2` are syntactically unrestricted patterns.
7 // If `binding` is allowed to influence `subpat`,
8 // this would create problems for the generalization aforementioned.
9
10 #![feature(bindings_after_at)]
11 #![feature(move_ref_pattern)]
12
13 fn main() {
14 struct NotCopy;
15
16 fn f1(a @ b: &NotCopy) { // OK
17 let _: &NotCopy = a;
18 }
19 fn f2(ref a @ b: &NotCopy) {
20 let _: &&NotCopy = a; // Ok
21 }
22
23 let a @ b = &NotCopy; // OK
24 let _: &NotCopy = a;
25 let ref a @ b = &NotCopy; // OK
26 let _: &&NotCopy = a;
27
28 let ref a @ b = NotCopy; //~ ERROR cannot move out of value because it is borrowed
29 let _a: &NotCopy = a;
30 let _b: NotCopy = b;
31 let ref mut a @ b = NotCopy; //~ ERROR cannot move out of value because it is borrowed
32 //~^ ERROR cannot move out of `_` because it is borrowed
33 let _a: &NotCopy = a;
34 let _b: NotCopy = b;
35 match Ok(NotCopy) {
36 Ok(ref a @ b) | Err(b @ ref a) => {
37 //~^ ERROR cannot move out of value because it is borrowed
38 //~| ERROR borrow of moved value
39 let _a: &NotCopy = a;
40 let _b: NotCopy = b;
41 }
42 }
43 match NotCopy {
44 ref a @ b => {
45 //~^ ERROR cannot move out of value because it is borrowed
46 let _a: &NotCopy = a;
47 let _b: NotCopy = b;
48 }
49 }
50 }