rust/tests/ui/borrowck/borrowck-auto-mut-ref-to-immut-var.rs

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

17 lines
271 B
Rust
Raw Normal View History

// Tests that auto-ref can't create mutable aliases to immutable memory.
struct Foo {
x: isize
}
impl Foo {
pub fn printme(&mut self) {
println!("{}", self.x);
}
}
fn main() {
let x = Foo { x: 3 };
2013-03-15 19:24:24 +00:00
x.printme(); //~ ERROR cannot borrow
}