diff --git a/src/core/option.rs b/src/core/option.rs index c4e2ef8..73a7daf 100644 --- a/src/core/option.rs +++ b/src/core/option.rs @@ -162,7 +162,7 @@ impl Core for OptionCore { unsafe fn has_element_at(&self, idx: usize) -> bool { debug_assert!(idx < self.cap()); - self.data.get_unchecked(idx).is_some() + idx < self.len() && self.data.get_unchecked(idx).is_some() } unsafe fn insert_at(&mut self, idx: usize, elem: T) { diff --git a/src/tests.rs b/src/tests.rs index a981070..a89bbe5 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -166,6 +166,7 @@ macro_rules! gen_tests_for { assert!(sv.capacity() >= 3); assert_sv_eq!(sv, []: String); + assert_eq!(sv.get(0), None); } #[test] @@ -896,6 +897,7 @@ macro_rules! gen_tests_for { let mut sv = $ty::from_iter(vec![1, 3, 5]); sv.clear(); assert_sv_eq!(sv, []: u32); + assert_eq!(sv.get(0), None); } #[test]