diff options
Diffstat (limited to 'src/libcore/tests')
| -rw-r--r-- | src/libcore/tests/slice.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index 7968521f7b4..b087ec81f59 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -986,3 +986,17 @@ fn test_align_to_non_trivial() { assert_eq!(aligned.len(), 4); assert_eq!(prefix.len() + suffix.len(), 2); } + +#[test] +fn test_align_to_empty_mid() { + use core::mem; + + // Make sure that we do not create empty unaligned slices for the mid part, even when the + // overall slice is too short to contain an aligned address. + let bytes = [1, 2, 3, 4, 5, 6, 7]; + type Chunk = u32; + for offset in 0..4 { + let (_, mid, _) = unsafe { bytes[offset..offset+1].align_to::<Chunk>() }; + assert_eq!(mid.as_ptr() as usize % mem::align_of::<Chunk>(), 0); + } +} |
