]> git.lizzy.rs Git - rust.git/blob - src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.rs
Remove `bindings_after_at` from `INCOMPLETE_FEATURES`.
[rust.git] / src / test / ui / pattern / bindings-after-at / borrowck-pat-ref-mut-twice.rs
1 // Test that `ref mut x @ ref mut y` and varieties of that are not allowed.
2
3 #![feature(bindings_after_at)]
4 #![feature(slice_patterns)]
5
6 fn main() {
7     struct U;
8
9     fn u() -> U { U }
10
11     fn f1(ref mut a @ ref mut b: U) {}
12     //~^ ERROR cannot borrow `a` as mutable more than once at a time
13     fn f2(ref mut a @ ref mut b: U) {}
14     //~^ ERROR cannot borrow `a` as mutable more than once at a time
15     fn f3(
16         ref mut a @ [
17         //~^ ERROR cannot borrow `a` as mutable more than once at a time
18             [ref b @ .., _],
19             [_, ref mut mid @ ..],
20             ..,
21             [..],
22         ] : [[U; 4]; 5]
23     ) {}
24
25     let ref mut a @ ref mut b = U;
26     //~^ ERROR cannot borrow `a` as mutable more than once at a time
27     //~| ERROR cannot borrow `_` as mutable more than once at a time
28     drop(a);
29     let ref mut a @ ref mut b = U;
30     //~^ ERROR cannot borrow `a` as mutable more than once at a time
31     drop(b);
32     let ref mut a @ ref mut b = U;
33     //~^ ERROR cannot borrow `a` as mutable more than once at a time
34
35     let ref mut a @ ref mut b = U;
36     //~^ ERROR cannot borrow `a` as mutable more than once at a time
37     //~| ERROR cannot borrow `_` as mutable more than once at a time
38     *a = U;
39     let ref mut a @ ref mut b = U;
40     //~^ ERROR cannot borrow `a` as mutable more than once at a time
41     *b = U;
42
43     let ref mut a @ (
44     //~^ ERROR cannot borrow `a` as mutable more than once at a time
45         ref mut b,
46         [
47             ref mut c,
48             ref mut d,
49             ref e,
50         ]
51     ) = (U, [U, U, U]);
52
53     let ref mut a @ (
54         //~^ ERROR cannot borrow `a` as mutable more than once at a time
55             ref mut b,
56             [
57                 ref mut c,
58                 ref mut d,
59                 ref e,
60             ]
61         ) = (u(), [u(), u(), u()]);
62
63     let a @ (ref mut b, ref mut c) = (U, U);
64     //~^ ERROR cannot bind by-move with sub-bindings
65     //~| ERROR borrow of moved value
66     let mut val = (U, [U, U]);
67     let a @ (b, [c, d]) = &mut val; // Same as ^--
68     //~^ ERROR cannot bind by-move with sub-bindings
69     //~| ERROR borrow of moved value
70
71     let a @ &mut ref mut b = &mut U;
72     //~^ ERROR cannot bind by-move with sub-bindings
73     //~| ERROR borrow of moved value
74     let a @ &mut (ref mut b, ref mut c) = &mut (U, U);
75     //~^ ERROR cannot bind by-move with sub-bindings
76     //~| ERROR borrow of moved value
77
78     match Ok(U) {
79         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
80             //~^ ERROR cannot borrow `a` as mutable more than once at a time
81             //~| ERROR cannot borrow `a` as mutable more than once at a time
82         }
83     }
84     match Ok(U) {
85         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
86             //~^ ERROR cannot borrow `a` as mutable more than once at a time
87             //~| ERROR cannot borrow `a` as mutable more than once at a time
88             *b = U;
89         }
90     }
91     match Ok(U) {
92         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
93             //~^ ERROR cannot borrow `a` as mutable more than once at a time
94             //~| ERROR cannot borrow `a` as mutable more than once at a time
95             //~| ERROR cannot borrow `_` as mutable more than once at a time
96             //~| ERROR cannot borrow `_` as mutable more than once at a time
97             *a = Err(U);
98
99             // FIXME: The binding name `_` used above makes for problematic diagnostics.
100             // Resolve that somehow...
101         }
102     }
103     match Ok(U) {
104         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
105             //~^ ERROR cannot borrow `a` as mutable more than once at a time
106             //~| ERROR cannot borrow `a` as mutable more than once at a time
107             //~| ERROR cannot borrow `_` as mutable more than once at a time
108             //~| ERROR cannot borrow `_` as mutable more than once at a time
109             drop(a);
110         }
111     }
112 }