Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 57 #58

Merged
merged 3 commits into from Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -2,7 +2,7 @@
# dev-dependencies which causes
[package]
name = "slice-deque"
version = "0.1.15"
version = "0.1.16"
authors = ["gnzlbg <gonzalobg88@gmail.com>"]
description = "A double-ended queue that Deref's into a slice."
documentation = "https://docs.rs/crate/slice-deque/"
Expand Down
27 changes: 23 additions & 4 deletions src/lib.rs
Expand Up @@ -748,7 +748,7 @@ impl<T> SliceDeque<T> {
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
Expand All @@ -765,6 +765,8 @@ impl<T> SliceDeque<T> {

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`.
Expand Down Expand Up @@ -4128,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());
Expand Down Expand Up @@ -4310,7 +4312,7 @@ mod tests {
_ => panic!("invalid `Cow::from`"),
}
}

#[test]
fn vec_from_cow() {
use std::borrow::Cow;
Expand All @@ -4323,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> {
Expand Down Expand Up @@ -5890,4 +5892,21 @@ mod tests {
assert_eq!(v.as_ptr() as usize, mem::align_of::<Foo>());
}
}

#[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);
}
}
}