]> git.lizzy.rs Git - rust.git/blob - tests/ui/methods/method-self-arg-2.rs
Rollup merge of #107499 - compiler-errors:deduce_sig_from_projection-generator-tweak...
[rust.git] / tests / ui / methods / method-self-arg-2.rs
1 // Test method calls with self as an argument cannot subvert borrow checking.
2
3
4
5 struct Foo;
6
7 impl Foo {
8     fn bar(&self) {}
9     fn baz(&mut self) {}
10 }
11
12 fn main() {
13     let mut x = Foo;
14     let y = &mut x;
15     Foo::bar(&x); //~ERROR cannot borrow `x`
16     y.use_mut();
17
18     let mut x = Foo;
19     let y = &mut x;
20     Foo::baz(&mut x); //~ERROR cannot borrow `x`
21     y.use_mut();
22 }
23
24 trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { }  }
25 impl<T> Fake for T { }