1 use std::alloc::{Allocator, Global, Layout, System};
3 /// Issue #45955 and #62251.
5 fn alloc_system_overaligned_request() {
6 check_overalign_requests(System)
10 fn std_heap_overaligned_request() {
11 check_overalign_requests(Global)
14 fn check_overalign_requests<T: Allocator>(allocator: T) {
15 for &align in &[4, 8, 16, 32] {
16 // less than and bigger than `MIN_ALIGN`
17 for &size in &[align / 2, align - 1] {
18 // size less than alignment
21 let pointers: Vec<_> = (0..iterations)
23 allocator.allocate(Layout::from_size_align(size, align).unwrap()).unwrap()
26 for &ptr in &pointers {
28 (ptr.as_non_null_ptr().as_ptr() as usize) % align,
30 "Got a pointer less aligned than requested"
35 for &ptr in &pointers {
37 ptr.as_non_null_ptr(),
38 Layout::from_size_align(size, align).unwrap(),