]> git.proxmox.com Git - rustc.git/blame - src/test/ui/methods/method-self-arg-2.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui / methods / method-self-arg-2.rs
CommitLineData
1a4d82fc 1// Test method calls with self as an argument cannot subvert borrow checking.
223e47cc 2
b7449926
XL
3
4
1a4d82fc 5struct Foo;
970d7e83 6
1a4d82fc
JJ
7impl Foo {
8 fn bar(&self) {}
9 fn baz(&mut self) {}
223e47cc
LB
10}
11
12fn main() {
1a4d82fc
JJ
13 let mut x = Foo;
14 let y = &mut x;
15 Foo::bar(&x); //~ERROR cannot borrow `x`
b7449926 16 y.use_mut();
1a4d82fc 17
85aaf69f
SL
18 let mut x = Foo;
19 let y = &mut x;
20 Foo::baz(&mut x); //~ERROR cannot borrow `x`
b7449926 21 y.use_mut();
223e47cc 22}
b7449926
XL
23
24trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
25impl<T> Fake for T { }