]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-anon-fields-variant.rs
Merge commit '48d60ab7c505c6c1ebb042eacaafd8dc9f7a9267' into libgccjit-codegen
[rust.git] / src / test / ui / borrowck / borrowck-anon-fields-variant.rs
1 enum Foo {
2     X, Y(usize, usize)
3 }
4
5 fn distinct_variant() {
6     let mut y = Foo::Y(1, 2);
7
8     let a = match y {
9       Foo::Y(ref mut a, _) => a,
10       Foo::X => panic!()
11     };
12
13     // While `a` and `b` are disjoint, borrowck doesn't know that `a` is not
14     // also used for the discriminant of `Foo`, which it would be if `a` was a
15     // reference.
16     let b = match y {
17       Foo::Y(_, ref mut b) => b,
18       //~^ ERROR cannot use `y`
19       Foo::X => panic!()
20     };
21
22     *a += 1;
23     *b += 1;
24 }
25
26 fn same_variant() {
27     let mut y = Foo::Y(1, 2);
28
29     let a = match y {
30       Foo::Y(ref mut a, _) => a,
31       Foo::X => panic!()
32     };
33
34     let b = match y {
35       Foo::Y(ref mut b, _) => b, //~ ERROR cannot use `y`
36       //~| ERROR cannot borrow `y.0` as mutable
37       Foo::X => panic!()
38     };
39
40     *a += 1;
41     *b += 1;
42 }
43
44 fn main() {
45 }