Add test for VecDeque::append ZST capacity overflow

(cherry picked from commit 12f959ba39)
This commit is contained in:
pommicket 2023-02-25 13:50:56 -05:00 committed by Josh Stone
parent 07a8043079
commit 005892a589

View file

@ -1045,6 +1045,20 @@ fn test_append_double_drop() {
assert_eq!(count_b, 1);
}
#[test]
#[should_panic]
fn test_append_zst_capacity_overflow() {
let mut v = Vec::with_capacity(usize::MAX);
// note: using resize instead of set_len here would
// be *extremely* slow in unoptimized builds.
// SAFETY: `v` has capacity `usize::MAX`, and no initialization
// is needed for empty tuples.
unsafe { v.set_len(usize::MAX) };
let mut v = VecDeque::from(v);
let mut w = vec![()].into();
v.append(&mut w);
}
#[test]
fn test_retain() {
let mut buf = VecDeque::new();