Closed
Description
Compiling this:
struct Foo {
x: int,
}
impl Foo {
pub fn get_x(&self) -> &'self int { &self.x }
}
struct Bar {
x: Foo,
}
impl Bar {
pub fn do_shit(&mut self) -> () { }
pub fn break_shit(&mut self) -> () {
let x = *self.x.get_x();
core::util::ignore(x);
self.do_shit()
}
}
fn main() {
let mut x = Bar { x: Foo { x: 1 } };
x.break_shit();
}
yields the error
shit.rs:20:2: 20:6 error: loan of dereference of mutable & pointer as mutable conflicts with prior loan
shit.rs:20 self.do_shit()
^~~~
shit.rs:16:10: 16:14 note: prior loan as immutable granted here
shit.rs:16 let y = self.x.get_x();
The self pointer is considered loaned out from 'let x = *self.x.get_x()', even though it... isn't.
Metadata
Metadata
Assignees
Labels
No labels