From 70c87a49451c4dfcb170461ad9c55fe2f104b7b4 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 5 Dec 2018 12:18:04 +0100 Subject: [PATCH 1/3] Fix issue 57 --- src/lib.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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); + } + } } From f0fe275733530f3e2dfacf4a8854d50e0a780b0d Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 5 Dec 2018 12:18:26 +0100 Subject: [PATCH 2/3] formatting --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 22ef3a6..1b62f3d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4130,7 +4130,7 @@ mod tests { } for _ in v.drain(usize::max_value() - 1..) {} assert_eq!(v.len(), usize::max_value() - 1); - + let mut v = SliceDeque::<()>::with_capacity(usize::max_value()); unsafe { v.set_len(usize::max_value()); @@ -4312,7 +4312,7 @@ mod tests { _ => panic!("invalid `Cow::from`"), } } - + #[test] fn vec_from_cow() { use std::borrow::Cow; @@ -4325,7 +4325,7 @@ mod tests { /* TODO: covariance use super::{Drain, IntoIter}; - + #[allow(dead_code)] fn assert_covariance() { fn drain<'new>(d: Drain<'static, &'static str>) -> Drain<'new, &'new str> { From 426aace1a3ef177b77ca53d75d6dc498aadfc3b1 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 5 Dec 2018 12:18:46 +0100 Subject: [PATCH 3/3] Bump patch version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5faabdd..dc60a25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ # dev-dependencies which causes [package] name = "slice-deque" -version = "0.1.15" +version = "0.1.16" authors = ["gnzlbg "] description = "A double-ended queue that Deref's into a slice." documentation = "https://docs.rs/crate/slice-deque/"