Skip to content

Instantly share code, notes, and snippets.

@jasom
Created September 15, 2014 21:23
Show Gist options
  • Save jasom/b4d9304c13120153534e to your computer and use it in GitHub Desktop.
Save jasom/b4d9304c13120153534e to your computer and use it in GitHub Desktop.
struct ExternalNode {
key: int,
value: int
}
fn main() {
let mut boxed_node = box ExternalNode{ key : 1, value: 2};
match boxed_node {
box ExternalNode{key : ref fkey, value: ref mut val} => {
*val+=1;
}
}
}
@jasom
Copy link
Author

jasom commented Sep 15, 2014

foo.rs:12:49: 12:60 error: cannot borrow `boxed_node.value` as mutable because `boxed_node.key` is also borrowed as immutable
foo.rs:12         box ExternalNode{key : ref fkey, value: ref mut val} => {
                                                          ^~~~~~~~~~~
foo.rs:12:32: 12:40 note: previous borrow of `boxed_node.key` occurs here; the immutable borrow prevents subsequent moves or mutable borrows of `boxed_node.key` until the borrow ends
foo.rs:12         box ExternalNode{key : ref fkey, value: ref mut val} => {
                                         ^~~~~~~~
foo.rs:15:6: 15:6 note: previous borrow ends here
foo.rs:11     match boxed_node {
foo.rs:12         box ExternalNode{key : ref fkey, value: ref mut val} => {
foo.rs:13          *val+=1;
foo.rs:14         }
foo.rs:15     }
              ^
error: aborting due to previous error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment