Skip to content

Commit bff26fc

Browse files
committed
Panic safety test for SmallVec::drop
A test for issue #14
1 parent 3e329f0 commit bff26fc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,4 +578,21 @@ pub mod tests {
578578

579579
assert_eq!(&v.iter().map(|v| **v).collect::<Vec<_>>(), &[0, 3, 2]);
580580
}
581+
582+
#[test]
583+
#[should_panic]
584+
fn test_drop_panic_smallvec() {
585+
// This test should only panic once, and not double panic,
586+
// which would mean a double drop
587+
struct DropPanic;
588+
589+
impl Drop for DropPanic {
590+
fn drop(&mut self) {
591+
panic!("drop");
592+
}
593+
}
594+
595+
let mut v = SmallVec::<[_; 1]>::new();
596+
v.push(DropPanic);
597+
}
581598
}

0 commit comments

Comments
 (0)