]> git.proxmox.com Git - rustc.git/blame - src/test/ui/borrowck/borrowck-object-lifetime.rs
New upstream version 1.36.0+dfsg1
[rustc.git] / src / test / ui / borrowck / borrowck-object-lifetime.rs
CommitLineData
1a4d82fc
JJ
1// Test that borrows that occur due to calls to object methods
2// properly "claim" the object path.
3
b7449926
XL
4
5
1a4d82fc
JJ
6trait Foo {
7 fn borrowed(&self) -> &();
8 fn mut_borrowed(&mut self) -> &();
9}
10
11fn borrowed_receiver(x: &Foo) {
b7449926
XL
12 let y = x.borrowed();
13 let z = x.borrowed();
14 z.use_ref();
15 y.use_ref();
1a4d82fc
JJ
16}
17
18fn mut_borrowed_receiver(x: &mut Foo) {
b7449926
XL
19 let y = x.borrowed();
20 let z = x.mut_borrowed(); //~ ERROR cannot borrow
21 y.use_ref();
1a4d82fc
JJ
22}
23
24fn mut_owned_receiver(mut x: Box<Foo>) {
b7449926
XL
25 let y = x.borrowed();
26 let z = &mut x; //~ ERROR cannot borrow
27 y.use_ref();
1a4d82fc
JJ
28}
29
30fn imm_owned_receiver(mut x: Box<Foo>) {
b7449926
XL
31 let y = x.borrowed();
32 let z = &x;
33 z.use_ref();
34 y.use_ref();
1a4d82fc
JJ
35}
36
37fn main() {}
b7449926
XL
38
39trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
40impl<T> Fake for T { }