rust/tests/ui/borrowck/issue-111554.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
641 B
Rust
Raw Normal View History

struct Foo {}
impl Foo {
pub fn foo(&mut self) {
|| bar(&mut self);
//~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable
}
pub fn baz(&self) {
|| bar(&mut self);
//~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable
//~| ERROR cannot borrow data in a `&` reference as mutable
}
pub fn qux(mut self) {
|| bar(&mut self);
// OK
}
pub fn quux(self) {
|| bar(&mut self);
//~^ ERROR cannot borrow `self` as mutable, as it is not declared as mutable
}
}
fn bar(_: &mut Foo) {}
fn main() {}