From 24fa9deddc8d5bf940ee89672cb819e802b39d43 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 25 Jul 2021 14:33:41 +0200 Subject: [PATCH] add test for mixing up System and Global memory --- tests/compile-fail/alloc/global_system_mixup.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/compile-fail/alloc/global_system_mixup.rs diff --git a/tests/compile-fail/alloc/global_system_mixup.rs b/tests/compile-fail/alloc/global_system_mixup.rs new file mode 100644 index 000000000000..afe9d5cc8254 --- /dev/null +++ b/tests/compile-fail/alloc/global_system_mixup.rs @@ -0,0 +1,13 @@ +// 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 + +#![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); } +}