Follow changes in rust master

Thanks to @jansegre who wrote most of this patch.