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