rust/tests/ui/span/borrowck-object-mutability.rs

27 lines
466 B
Rust
Raw Normal View History

trait Foo {
fn borrowed(&self);
fn borrowed_mut(&mut self);
}
2019-05-28 13:46:13 -05:00
fn borrowed_receiver(x: &dyn Foo) {
x.borrowed();
x.borrowed_mut(); //~ ERROR cannot borrow
}
2019-05-28 13:46:13 -05:00
fn borrowed_mut_receiver(x: &mut dyn Foo) {
x.borrowed();
x.borrowed_mut();
}
2019-05-28 13:46:13 -05:00
fn owned_receiver(x: Box<dyn Foo>) {
x.borrowed();
x.borrowed_mut(); //~ ERROR cannot borrow
}
2019-05-28 13:46:13 -05:00
fn mut_owned_receiver(mut x: Box<dyn Foo>) {
x.borrowed();
x.borrowed_mut();
}
fn main() {}