]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-borrow-mut-object-twice.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-borrow-mut-object-twice.rs
1 // Check that `&mut` objects cannot be borrowed twice, just like
2 // other `&mut` pointers.
3
4
5
6 trait Foo {
7     fn f1(&mut self) -> &();
8     fn f2(&mut self);
9 }
10
11 fn test(x: &mut dyn Foo) {
12     let y = x.f1();
13     x.f2(); //~ ERROR cannot borrow `*x` as mutable
14     y.use_ref();
15 }
16
17 fn main() {}
18
19 trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { }  }
20 impl<T> Fake for T { }