Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis nikomatsakis/borrowck-error-new.txt Secret
Last active Nov 18, 2015

Embed
What would you like to do?
borrowck errors
example.rs:17:5: 17:9 error: cannot borrow `data` as mutable because it is
also borrowed as immutable
example.rs:17 let name = find_id(&data, 22).unwrap();
^~~~~ <-- immutable borrow begins here
example.rs:18
example.rs:19 // Add one more item we forgot to the vector. Silly us.
example.rs:20 data.push(Data { name: format!("Hera"), id: 66 });
^~~~ <-- mutable borrow occurs here
example.rs:21
example.rs:22 // Print everything out.
example.rs:23 println!("Name: {:?}", name);
example.rs:24 println!("Data: {:?}", data);
example.rs:25 }
^ <-- immutable borrow ends here
example.rs:17:5: 17:9 error: cannot borrow `data` as mutable because it is
also borrowed as immutable
example.rs:17 data.push(Data { name: format!("Hera"), id: 66 });
^~~~
example.rs:14:25: 14:29 note: previous borrow of `data` occurs here;
the immutable borrow prevents subsequent moves
or mutable borrows of `data` until the borrow ends
example.rs:14 let name = find_id(&data, 22).unwrap();
^~~~
example.rs:22:2: 22:2 note: previous borrow ends here
example.rs:7 fn main() {
...
example.rs:22 }
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.