diff options
| author | Ralf Jung <post@ralfj.de> | 2018-08-02 16:51:54 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2018-08-02 17:32:24 +0200 |
| commit | 6fb97a6c86e792552d330c7ab9db6f39ba28efb1 (patch) | |
| tree | ad838923aca82e197b1334616e5c221b03aeaee5 /src/libcore/tests | |
| parent | 7b24d2bb351efeea9c0109d8a662b1038fe8f539 (diff) | |
| download | rust-6fb97a6c86e792552d330c7ab9db6f39ba28efb1.tar.gz rust-6fb97a6c86e792552d330c7ab9db6f39ba28efb1.zip | |
test that align_of handles alignment properly for the mid part
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); + } +} |
