rust/tests/ui/borrowck/borrowck-borrow-mut-object-twice.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

21 lines
380 B
Rust
Raw Normal View History

// Check that `&mut` objects cannot be borrowed twice, just like
// other `&mut` pointers.
2012-10-31 22:09:26 +00:00
trait Foo {
fn f1(&mut self) -> &();
fn f2(&mut self);
2012-10-31 22:09:26 +00:00
}
2019-05-28 18:46:13 +00:00
fn test(x: &mut dyn Foo) {
let y = x.f1();
x.f2(); //~ ERROR cannot borrow `*x` as mutable
y.use_ref();
2012-10-31 22:09:26 +00:00
}
fn main() {}
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }