2014-08-27 21:46:52 -04:00
|
|
|
// Test that borrows that occur due to calls to object methods
|
|
|
|
// properly "claim" the object path.
|
2014-05-05 18:56:44 -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 borrowed(&self) -> &();
|
2014-08-27 21:46:52 -04:00
|
|
|
fn mut_borrowed(&mut self) -> &();
|
2013-08-11 13:58:48 -04:00
|
|
|
}
|
|
|
|
|
2019-05-28 14:46:13 -04:00
|
|
|
fn borrowed_receiver(x: &dyn Foo) {
|
2018-08-15 01:16:05 +02:00
|
|
|
let y = x.borrowed();
|
|
|
|
let z = x.borrowed();
|
|
|
|
z.use_ref();
|
|
|
|
y.use_ref();
|
2013-08-11 13:58:48 -04:00
|
|
|
}
|
|
|
|
|
2019-05-28 14:46:13 -04:00
|
|
|
fn mut_borrowed_receiver(x: &mut dyn Foo) {
|
2018-08-15 01:16:05 +02:00
|
|
|
let y = x.borrowed();
|
|
|
|
let z = x.mut_borrowed(); //~ ERROR cannot borrow
|
|
|
|
y.use_ref();
|
2013-08-11 13:58:48 -04:00
|
|
|
}
|
|
|
|
|
2019-05-28 14:46:13 -04:00
|
|
|
fn mut_owned_receiver(mut x: Box<dyn Foo>) {
|
2018-08-15 01:16:05 +02:00
|
|
|
let y = x.borrowed();
|
|
|
|
let z = &mut x; //~ ERROR cannot borrow
|
|
|
|
y.use_ref();
|
2013-08-11 13:58:48 -04:00
|
|
|
}
|
|
|
|
|
2019-05-28 14:46:13 -04:00
|
|
|
fn imm_owned_receiver(mut x: Box<dyn Foo>) {
|
2018-08-15 01:16:05 +02:00
|
|
|
let y = x.borrowed();
|
|
|
|
let z = &x;
|
|
|
|
z.use_ref();
|
|
|
|
y.use_ref();
|
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 { }
|