]> git.lizzy.rs Git - rust.git/blobdiff - tests/compile-fail/reallocate-dangling.rs
Auto merge of #1308 - RalfJung:miri, r=RalfJung
[rust.git] / tests / compile-fail / reallocate-dangling.rs
index ee73cfce8634be4dc68d5a728f42b254a3b66ba8..702ddc0724a33af8abc898d74e2318f485e237b3 100644 (file)
@@ -1,16 +1,11 @@
-#![feature(allocator_api)]
+use std::alloc::{alloc, dealloc, realloc, Layout};
 
-extern crate alloc;
-
-use alloc::alloc::Global;
-use std::alloc::{AllocRef, Layout};
-
-// error-pattern: dangling pointer was dereferenced
+// error-pattern: dereferenced after this allocation got freed
 
 fn main() {
     unsafe {
-        let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap();
-        Global.dealloc(x, Layout::from_size_align_unchecked(1, 1));
-        Global.realloc(x, Layout::from_size_align_unchecked(1, 1), 1).unwrap();
+        let x = alloc(Layout::from_size_align_unchecked(1, 1));
+        dealloc(x, Layout::from_size_align_unchecked(1, 1));
+        realloc(x, Layout::from_size_align_unchecked(1, 1), 1);
     }
 }