Use NoDrop to fix panic safety issues

ArrayVec::drop was not panic safe — if there would be a panic during an
element's drop, the discriminant would never be set to Dropped, and the
array elements would potentially double drop.

Fix this by going back to the old NoDrop composition. The NoDrop struct
thas its own Drop impl, that will trigger too on panic during an element's
drop. This serves to make ArrayVec::drop panic safe.

Also tweak IntoIter::drop to make it panic safe: set inner ArrayVec's
length before dropping any elements.

Thank you to @Stebalien for reporting this bug and providing the
excellent testcases in this commit.

Using NoDrop expands ArrayVec to have two drop flags again, but this
is a temporary tradeoff, drop flags will eventually go away.

Fixes #3
This commit is contained in:
bluss
2015-08-20 22:11:01 +02:00
parent 804fb9692a
commit c35760e02c
3 changed files with 56 additions and 48 deletions
+3 -3
View File
@@ -13,6 +13,6 @@ keywords = ["stack", "vector", "array", "container", "data-structure"]
[dependencies.odds]
version = "0.2"
[dev-dependencies]
nodrop = "0.1"
[dependencies.nodrop]
version = "0.1.4"
path = "nodrop"