mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Rollup merge of #108462 - pommicket:fix-vecdeque-zst-overflow, r=Amanieu
Fix `VecDeque::append` capacity overflow for ZSTs Fixes #108454.
This commit is contained in:
commit
093a53f134
@ -1924,7 +1924,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
|
||||
#[stable(feature = "append", since = "1.4.0")]
|
||||
pub fn append(&mut self, other: &mut Self) {
|
||||
if T::IS_ZST {
|
||||
self.len += other.len;
|
||||
self.len = self.len.checked_add(other.len).expect("capacity overflow");
|
||||
other.len = 0;
|
||||
other.head = 0;
|
||||
return;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user