Ported to rust master.