diff --git a/src/lib.rs b/src/lib.rs index de6c3f8..d2d6904 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -237,13 +237,15 @@ impl RawSmallVec { // SAFETY: it is safe because we aren't reading the value, just getting // a reference to it. reading it would be UB potentially, but // for that downstream unsafe is required - (unsafe { &raw const self.inline }) as *mut T + #[allow(unused_unsafe, reason = "Unsafe in MSRV")] + (unsafe { &raw const self.inline }).cast() } #[inline] const fn as_mut_ptr_inline(&mut self) -> *mut T { // SAFETY: same as above - (unsafe { &raw mut self.inline }) as *mut T + #[allow(unused_unsafe, reason = "Unsafe in MSRV")] + (unsafe { &raw mut self.inline }).cast() } /// # Safety diff --git a/tests/macro.rs b/tests/macro.rs index a5d3a71..913208a 100644 --- a/tests/macro.rs +++ b/tests/macro.rs @@ -1,7 +1,5 @@ -/// This file tests `smallvec!` without actually having the macro in scope. -/// This forces any recursion to use a `$crate` prefix to reliably find itself. - #[test] +#[allow(deprecated)] fn smallvec() { let mut vec: smallvec::SmallVec; diff --git a/tests/main.rs b/tests/main.rs index f8617f7..91bddef 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -3,10 +3,7 @@ use { hash::Hasher, iter::FromIterator }, - smallvec::{ - SmallVec, - smallvec - }, + smallvec::SmallVec, std::{ borrow::ToOwned, boxed::Box, @@ -176,7 +173,7 @@ fn drain_rev() { #[test] fn drain_forget() { - let mut v: SmallVec = smallvec![0, 1, 2, 3, 4, 5, 6, 7]; + let mut v: SmallVec = SmallVec::from([0, 1, 2, 3, 4, 5, 6, 7]); std::mem::forget(v.drain(2..5)); assert_eq!(v.len(), 2); } @@ -184,21 +181,21 @@ fn drain_forget() { #[test] fn splice() { // The range starts right before the end. - let mut v: SmallVec = smallvec![0, 1, 2, 3, 4, 5, 6]; + let mut v: SmallVec = SmallVec::from([0, 1, 2, 3, 4, 5, 6]); let new = [7, 8, 9, 10]; let u: SmallVec = v.splice(6.., new).collect(); assert_eq!(v, [0, 1, 2, 3, 4, 5, 7, 8, 9, 10]); assert_eq!(u, [6]); // The range is empty. - let mut v: SmallVec = smallvec![0, 1, 2, 3, 4, 5, 6]; + let mut v: SmallVec = SmallVec::from([0, 1, 2, 3, 4, 5, 6]); let new = [7, 8, 9, 10]; let u: SmallVec = v.splice(1..1, new).collect(); assert_eq!(v, [0, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6]); assert_eq!(u, [0u8; 0]); // The range is at the beginning and nonempty. - let mut v: SmallVec = smallvec![0, 1, 2, 3, 4, 5, 6]; + let mut v: SmallVec = SmallVec::from([0, 1, 2, 3, 4, 5, 6]); let new = [7, 8, 9, 10]; let u: SmallVec = v.splice(..3, new).collect(); assert_eq!(v, [7, 8, 9, 10, 3, 4, 5, 6]); @@ -347,7 +344,7 @@ fn test_truncate_references() { #[test] fn test_split_off() { - let mut vec: SmallVec = smallvec![1, 2, 3, 4, 5, 6]; + let mut vec: SmallVec = SmallVec::from([1, 2, 3, 4, 5, 6]); let orig_ptr = vec.as_ptr(); let orig_capacity = vec.capacity(); @@ -409,7 +406,7 @@ fn test_invalid_grow() { #[test] #[should_panic] fn drain_overflow() { - let mut v: SmallVec = smallvec![0]; + let mut v: SmallVec = SmallVec::from([0]); v.drain(..=usize::MAX); } @@ -429,7 +426,7 @@ fn test_extend_from_slice() { #[test] fn test_extend_from_within() { - let mut v: SmallVec = smallvec![0, 1, 2, 3]; + let mut v: SmallVec = SmallVec::from([0, 1, 2, 3]); v.extend_from_within(1..3); assert_eq!( &v.iter().map(|v| *v).collect::>(), @@ -714,15 +711,16 @@ fn test_into_vec() { #[test] fn test_into_inner() { let vec = SmallVec::::from_iter(0..2); - assert_eq!(vec.into_inner(), Ok([0, 1])); + assert_eq!(vec.try_into(), Ok([0, 1])); let vec = SmallVec::::from_iter(0..1); - assert_eq!(vec.clone().into_inner(), Err(vec)); + assert_eq!(vec.clone().try_into(), Err::<[u8; 7], SmallVec>(vec)); let vec = SmallVec::::from_iter(0..3); - assert_eq!(vec.clone().into_inner(), Err(vec)); + assert_eq!(vec.clone().try_into(), Err::<[u8; 1], SmallVec>(vec)); } +#[test] fn test_try_into_array() { // Inline < capacity let vec = SmallVec::::from_iter(0..1); @@ -915,15 +913,10 @@ const fn const_new_inner() -> SmallVec { SmallVec::::new() } const fn const_new_inline_sized() -> SmallVec { - smallvec::smallvec_inline![1; 4] + SmallVec::from_buf([1; 4]) } const fn const_new_inline_args() -> SmallVec { - smallvec::smallvec_inline![1, 4] -} - -#[test] -fn empty_macro() { - let _v: SmallVec = smallvec![]; + SmallVec::from_buf([1, 4]) } #[test] @@ -955,7 +948,7 @@ fn test_clone_from() { #[test] fn test_extract_if() { - let mut a: SmallVec = smallvec![0, 1u8, 2, 3, 4, 5, 6, 7, 8, 0]; + let mut a: SmallVec = SmallVec::from([0, 1u8, 2, 3, 4, 5, 6, 7, 8, 0]); let b: SmallVec = a.extract_if(1..9, |x| *x % 3 == 0).collect(); @@ -972,7 +965,7 @@ fn test_extract_if() { /// wrong" args. #[test] fn max_dont_panic() { - let mut sv: SmallVec = smallvec![0]; + let mut sv: SmallVec = SmallVec::from([0]); let _ = sv.get(usize::MAX); sv.truncate(usize::MAX); } @@ -980,21 +973,21 @@ fn max_dont_panic() { #[test] #[should_panic] fn max_remove() { - let mut sv: SmallVec = smallvec![0]; + let mut sv: SmallVec = SmallVec::from([0]); sv.remove(usize::MAX); } #[test] #[should_panic] fn max_swap_remove() { - let mut sv: SmallVec = smallvec![0]; + let mut sv: SmallVec = SmallVec::from([0]); sv.swap_remove(usize::MAX); } #[test] #[should_panic] fn max_insert() { - let mut sv: SmallVec = smallvec![0]; + let mut sv: SmallVec = SmallVec::from([0]); sv.insert(usize::MAX, 0); }