rust/tests/fail/alloc/global_system_mixup.rs
2022-06-01 10:53:38 -04:00

18 lines
705 B
Rust

// Make sure we detect when the `Global` and `System` allocators are mixed
// (even when the default `Global` uses `System`).
// error-pattern: which is Rust heap memory, using
// normalize-stderr-test: "using [A-Za-z]+ heap deallocation operation" -> "using PLATFORM heap deallocation operation"
// normalize-stderr-test: "\| +\^+" -> "| ^"
// normalize-stderr-test: "libc::free\([^()]*\)|unsafe \{ HeapFree\([^()]*\) \};" -> "FREE();"
#![feature(allocator_api, slice_ptr_get)]
use std::alloc::{Allocator, Global, System, Layout};
fn main() {
let l = Layout::from_size_align(1, 1).unwrap();
let ptr = Global.allocate(l).unwrap().as_non_null_ptr();
unsafe { System.deallocate(ptr, l); }
}