Upstream change: std::{cast → mem}::transmute*.
Use the new HashMap.find_with_or_insert_with.

Also tidy up a couple of other bits.