Skip to content

Commit 708e319

Browse files
committed
Auto merge of #29545 - mystor:vec-deque-test-panic, r=bluss
I think this should fix the test failures in debug mode from #29492 The assertion was written incorrectly, and I don't like the way the new assertion is written, but I _think_ it does the right thing now.
2 parents 2a7bd08 + 26db717 commit 708e319

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/libcollections/vec_deque.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ impl<T> VecDeque<T> {
148148
/// Copies a contiguous block of memory len long from src to dst
149149
#[inline]
150150
unsafe fn copy(&self, dst: usize, src: usize, len: usize) {
151-
debug_assert!(dst + len <= self.cap(), "dst={} src={} len={} cap={}", dst, src, len,
151+
debug_assert!(dst + len <= self.cap(), "cpy dst={} src={} len={} cap={}", dst, src, len,
152152
self.cap());
153-
debug_assert!(src + len <= self.cap(), "dst={} src={} len={} cap={}", dst, src, len,
153+
debug_assert!(src + len <= self.cap(), "cpy dst={} src={} len={} cap={}", dst, src, len,
154154
self.cap());
155155
ptr::copy(
156156
self.ptr().offset(src as isize),
@@ -161,9 +161,9 @@ impl<T> VecDeque<T> {
161161
/// Copies a contiguous block of memory len long from src to dst
162162
#[inline]
163163
unsafe fn copy_nonoverlapping(&self, dst: usize, src: usize, len: usize) {
164-
debug_assert!(dst + len <= self.cap(), "dst={} src={} len={} cap={}", dst, src, len,
164+
debug_assert!(dst + len <= self.cap(), "cno dst={} src={} len={} cap={}", dst, src, len,
165165
self.cap());
166-
debug_assert!(src + len <= self.cap(), "dst={} src={} len={} cap={}", dst, src, len,
166+
debug_assert!(src + len <= self.cap(), "cno dst={} src={} len={} cap={}", dst, src, len,
167167
self.cap());
168168
ptr::copy_nonoverlapping(
169169
self.ptr().offset(src as isize),
@@ -175,9 +175,11 @@ impl<T> VecDeque<T> {
175175
/// (abs(dst - src) + len) must be no larger than cap() (There must be at
176176
/// most one continuous overlapping region between src and dest).
177177
unsafe fn wrap_copy(&self, dst: usize, src: usize, len: usize) {
178-
debug_assert!(
179-
(if src <= dst { dst - src } else { src - dst }) + len <= self.cap(),
180-
"dst={} src={} len={} cap={}", dst, src, len, self.cap());
178+
#[allow(dead_code)]
179+
fn diff(a: usize, b: usize) -> usize {if a <= b {b - a} else {a - b}}
180+
debug_assert!(cmp::min(diff(dst, src),
181+
self.cap() - diff(dst, src)) + len <= self.cap(),
182+
"wrc dst={} src={} len={} cap={}", dst, src, len, self.cap());
181183

182184
if src == dst || len == 0 { return }
183185

0 commit comments

Comments
 (0)