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