]> git.lizzy.rs Git - rust.git/commitdiff
add test for mixing up System and Global memory
authorRalf Jung <post@ralfj.de>
Sun, 25 Jul 2021 12:33:41 +0000 (14:33 +0200)
committerRalf Jung <post@ralfj.de>
Sun, 25 Jul 2021 12:36:00 +0000 (14:36 +0200)
tests/compile-fail/alloc/global_system_mixup.rs [new file with mode: 0644]

diff --git a/tests/compile-fail/alloc/global_system_mixup.rs b/tests/compile-fail/alloc/global_system_mixup.rs
new file mode 100644 (file)
index 0000000..afe9d5c
--- /dev/null
@@ -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); }
+}