https://doc.rust-lang.org/nomicon/lifetime-mismatch.html#improperly-reduced-borrows states the code below will not compile:
fn get_default<'m, K, V>(map: &'m mut HashMap<K, V>, key: K) -> &'m mut V
where
K: Clone + Eq + Hash,
V: Default,
{
match map.get_mut(&key) {
Some(value) => value,
None => {
map.insert(key.clone(), V::default());
map.get_mut(&key).unwrap()
}
}
}
However, on nightly it will now compile due to Polonius Alpha being enabled (https://blog.rust-lang.org/2026/08/04/enabling-polonius-alpha-on-nightly/), it may be worth mentioning this.
Additionally, the name of the function should probably be get_mut_or_default as it is in the article.
https://doc.rust-lang.org/nomicon/lifetime-mismatch.html#improperly-reduced-borrows states the code below will not compile:
However, on nightly it will now compile due to Polonius Alpha being enabled (https://blog.rust-lang.org/2026/08/04/enabling-polonius-alpha-on-nightly/), it may be worth mentioning this.
Additionally, the name of the function should probably be
get_mut_or_defaultas it is in the article.