Rollup merge of #151769 - Qelxiros:vecdeque_splice_fix, r=joboet

fix undefined behavior in VecDeque::splice

closes rust-lang/rust#151758
This commit is contained in:
Jonathan Brouwer 2026-01-28 21:10:53 +01:00 committed by GitHub
commit 3ffbf6e692
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View file

@ -143,7 +143,11 @@ impl<T, A: Allocator> Drain<'_, T, A> {
let new_tail_start = tail_start + additional;
unsafe {
deque.wrap_copy(tail_start, new_tail_start, self.tail_len);
deque.wrap_copy(
deque.to_physical_idx(tail_start),
deque.to_physical_idx(new_tail_start),
self.tail_len,
);
}
self.drain_len += additional;
}

View file

@ -2336,3 +2336,14 @@ fn test_splice_forget() {
std::mem::forget(v.splice(2..4, a));
assert_eq!(v, &[1, 2]);
}
#[test]
fn test_splice_wrapping() {
let mut vec = VecDeque::with_capacity(10);
vec.push_front(7u8);
vec.push_back(9);
vec.splice(1..1, [8]);
assert_eq!(Vec::from(vec), [7, 8, 9]);
}