]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrow-tuple-fields.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrow-tuple-fields.rs
1 struct Foo(Box<isize>, isize);
2
3 struct Bar(isize, isize);
4
5
6
7
8
9 fn main() {
10     let x: (Box<_>, _) = (Box::new(1), 2);
11     let r = &x.0;
12     let y = x; //~ ERROR cannot move out of `x` because it is borrowed
13
14     r.use_ref();
15
16     let mut x = (1, 2);
17     let a = &x.0;
18     let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable because it is also borrowed as
19     a.use_ref();
20
21     let mut x = (1, 2);
22     let a = &mut x.0;
23     let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable more than once at a time
24     a.use_ref();
25
26     let x = Foo(Box::new(1), 2);
27     let r = &x.0;
28     let y = x; //~ ERROR cannot move out of `x` because it is borrowed
29     r.use_ref();
30
31     let mut x = Bar(1, 2);
32     let a = &x.0;
33     let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable because it is also borrowed as
34     a.use_ref();
35
36     let mut x = Bar(1, 2);
37     let a = &mut x.0;
38     let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable more than once at a time
39     a.use_mut();
40 }
41
42 trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { }  }
43 impl<T> Fake for T { }