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