]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-anon-fields-struct.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-anon-fields-struct.rs
1 // Tests that we are able to distinguish when loans borrow different
2 // anonymous fields of a tuple vs the same anonymous field.
3
4 struct Y(usize, usize);
5
6 fn distinct_variant() {
7     let mut y = Y(1, 2);
8
9     let a = match y {
10         Y(ref mut a, _) => a
11     };
12
13     let b = match y {
14         Y(_, ref mut b) => b
15     };
16
17     *a += 1;
18     *b += 1;
19 }
20
21 fn same_variant() {
22     let mut y = Y(1, 2);
23
24     let a = match y {
25         Y(ref mut a, _) => a
26     };
27
28     let b = match y {
29         Y(ref mut b, _) => b //~ ERROR cannot borrow
30     };
31
32     *a += 1;
33     *b += 1;
34 }
35
36 fn main() {
37 }