Skip to content

Instantly share code, notes, and snippets.

@gchp
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gchp/5c5861888f2a345fa0b1 to your computer and use it in GitHub Desktop.
Save gchp/5c5861888f2a345fa0b1 to your computer and use it in GitHub Desktop.
Dereference error
type Link = Option<Box<Line>>;
struct Cursor {
line: Link,
}
struct Line {
next: Link,
value: String,
}
struct Buffer {
head: Link,
cursor: Cursor,
}
impl Buffer {
pub fn set_cursor(&mut self) {
self.cursor.line = self.head;
}
pub fn do_something_else(&self) {}
}
fn main() {
let mut buffer = Buffer {
head: None,
cursor: Cursor { line: None }
};
buffer.set_cursor();
buffer.do_something_else();
}
/*
This gives an error:
$ rustc main.rs
error.rs:19:28: 19:32 error: cannot move out of dereference of `&mut`-pointer
error.rs:19 self.cursor.line = self.head;
^~~~
error: aborting due to previous error
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment