diff --git a/src/lib.rs b/src/lib.rs index ecd0eb1..22ef3a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -748,7 +748,7 @@ impl SliceDeque { new_head += cap as isize; debug_assert!(new_head >= 0); self.tail_ += cap; - } else if new_head as usize > cap { + } else if new_head as usize >= cap { // cannot panic because new_head >= 0 // If the new head is larger than the capacity, we shift the range // by -capacity to move it towards the first mirrored @@ -765,6 +765,8 @@ impl SliceDeque { debug_assert!(self.tail() <= self.tail_upper_bound()); debug_assert!(self.head() <= self.head_upper_bound()); + + debug_assert!(self.head() != self.capacity()); } /// Moves the deque head by `x`. @@ -5890,4 +5892,21 @@ mod tests { assert_eq!(v.as_ptr() as usize, mem::align_of::()); } } + + #[test] + fn issue_57() { + const C: [i16; 3] = [42; 3]; + + let mut deque = SliceDeque::new(); + + for _ in 0..918 { + deque.push_front(C); + } + + for _ in 0..237 { + assert_eq!(deque.pop_front(), Some(C)); + assert!(!deque.is_empty()); + assert_eq!(*deque.back().unwrap(), C); + } + } }