2013-08-11 13:58:48 -04:00
|
|
|
// Check that `&mut` objects cannot be borrowed twice, just like
|
|
|
|
// other `&mut` pointers.
|
2012-10-31 15:09:26 -07:00
|
|
|
|
2018-08-15 01:16:05 +02:00
|
|
|
|
|
|
|
|
2013-08-11 13:58:48 -04:00
|
|
|
trait Foo {
|
2014-07-17 21:44:59 -07:00
|
|
|
fn f1(&mut self) -> &();
|
2013-08-11 13:58:48 -04:00
|
|
|
fn f2(&mut self);
|
2012-10-31 15:09:26 -07:00
|
|
|
}
|
|
|
|
|
2019-05-28 14:46:13 -04:00
|
|
|
fn test(x: &mut dyn Foo) {
|
2018-08-15 01:16:05 +02:00
|
|
|
let y = x.f1();
|
2014-02-10 07:44:03 -05:00
|
|
|
x.f2(); //~ ERROR cannot borrow `*x` as mutable
|
2018-08-15 01:16:05 +02:00
|
|
|
y.use_ref();
|
2012-10-31 15:09:26 -07:00
|
|
|
}
|
|
|
|
|
2013-08-11 13:58:48 -04:00
|
|
|
fn main() {}
|
2018-08-15 01:16:05 +02:00
|
|
|
|
|
|
|
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
|
|
|
|
impl<T> Fake for T { }
|