IIRC, the borrowchk did not accept the following code, it is a target of next borrow cheker
But today, I found the code was accepted.
I don't know when the change was made, or else it is just not the exactly piece of the refused code.
use std::collections::HashMap;
pub fn insert_or_update(k: &str, v: i32) {
let mut hash: HashMap<String, i32> = Default::default();
match hash.get_mut(k) {
Some(res) => *res = v,
None => {
hash.insert(k.to_owned(), v);
}
}
}