Add Array impl for [T; 0]

This commit is contained in:
Vurich
2018-03-20 14:49:49 +01:00
parent cb0244fbef
commit 1fd1ff5640
+12 -3
View File
@@ -1132,14 +1132,14 @@ macro_rules! impl_array(
unsafe impl<T> Array for [T; $size] {
type Item = T;
fn size() -> usize { $size }
fn ptr(&self) -> *const T { &self[0] }
fn ptr_mut(&mut self) -> *mut T { &mut self[0] }
fn ptr(&self) -> *const T { self.as_ptr() }
fn ptr_mut(&mut self) -> *mut T { self.as_mut_ptr() }
}
)+
}
);
impl_array!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32, 36,
impl_array!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32, 36,
0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000,
0x10000, 0x20000, 0x40000, 0x80000, 0x100000);
@@ -1162,6 +1162,15 @@ mod tests {
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
#[test]
pub fn test_zero() {
let mut v = SmallVec::<[_; 0]>::new();
assert!(!v.spilled());
v.push(0usize);
assert!(v.spilled());
assert_eq!(&*v, &[0]);
}
// We heap allocate all these strings so that double frees will show up under valgrind.
#[test]