This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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