std: Make vec::from_fn failure-safe
auto merge of #8766 : brson/rust/vecfromfn, r=alexcrichton

A recently-enabled test of this is causing valgrind failures.