Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Created January 29, 2013 06:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save alexcrichton/4662282 to your computer and use it in GitHub Desktop.
use core::hashmap::linear::LinearMap;
fn fun1() {
let mut map = LinearMap::new();
map.insert(1, 2);
// ok
let size;
size = *map.get(&1);
map.insert(2, size);
}
fn fun2() {
let mut map = LinearMap::new();
map.insert(1, 2);
let size = *map.get(&1); // note: prior loan of immutable granted here
map.insert(2, size); // error: loan of mutable local variable as mutable conflicts with prior loan
}
fn fun3() {
let mut map = LinearMap::new();
map.insert(1, 2);
// more bad, same as fun2
map.insert(2, *map.get(&1));
}
fn main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment