Fixed Stacked Borrows violations in ArrayVec crate

49 points angelicosphosphoros

ArrayVec is very popular crate (49 millions of downloads) that implements Vec-like interface on top of an array. Unfortunately, recently introduced Stacked Borrows verifications in MIRI don't accept code in the crate (mostly because every call of as_ptr and as_mut_ptr borrows whole backing array while another used pointer still exists).

This made miri tests on my project mostly useless because instead of checking my code it failed in ArrayVec code.

I decided to fix those errors.

You can use my fixed code until it is merged to upstream by changing arrayvec addition in you Cargo.toml to this:

arrayvec = {
   git = "https://github.com/AngelicosPhosphoros/arrayvec.git",
   rev = "bee0ffc5425690cbdc1ab31453b01e6a520b1484"
}

If you don't trust me, you can review my changes here. Since you specify exact git revision in your Cargo.toml, I cannot change code that you would pull.

Hope that it helps somebody.

Edit: rebased my branch so cargo fmt is the first commit, added tests and fixed one case I missed originally. If you want to look at diff without cargo fmt changes, look at https://github.com/AngelicosPhosphoros/arrayvec/compare/5e7d3d52891dda390d3d38df17e7c598ce8b38e9..bee0ffc5425690cbdc1ab31453b01e6a520b1484