about summary refs log tree commit diff
path: root/src/test/ui/allocator/custom.rs
diff options
context:
space:
mode:
authorAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-05 09:13:28 +0100
committerAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-11 09:32:08 +0000
commitcf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch)
tree40a88d9a46aaf3e8870676eb2538378b75a263eb /src/test/ui/allocator/custom.rs
parentca855e6e42787ecd062d81d53336fe6788ef51a9 (diff)
downloadrust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz
rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip
Move /src/test to /tests
Diffstat (limited to 'src/test/ui/allocator/custom.rs')
-rw-r--r--src/test/ui/allocator/custom.rs59
1 files changed, 0 insertions, 59 deletions
diff --git a/src/test/ui/allocator/custom.rs b/src/test/ui/allocator/custom.rs
deleted file mode 100644
index 10cbc23c427..00000000000
--- a/src/test/ui/allocator/custom.rs
+++ /dev/null
@@ -1,59 +0,0 @@
-// run-pass
-
-// aux-build:helper.rs
-// no-prefer-dynamic
-
-#![feature(allocator_api)]
-#![feature(slice_ptr_get)]
-
-extern crate helper;
-
-use std::alloc::{self, Allocator, Global, Layout, System};
-use std::sync::atomic::{AtomicUsize, Ordering};
-
-static HITS: AtomicUsize = AtomicUsize::new(0);
-
-struct A;
-
-unsafe impl alloc::GlobalAlloc for A {
-    unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
-        HITS.fetch_add(1, Ordering::SeqCst);
-        alloc::GlobalAlloc::alloc(&System, layout)
-    }
-
-    unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
-        HITS.fetch_add(1, Ordering::SeqCst);
-        alloc::GlobalAlloc::dealloc(&System, ptr, layout)
-    }
-}
-
-#[global_allocator]
-static GLOBAL: A = A;
-
-fn main() {
-    println!("hello!");
-
-    let n = HITS.load(Ordering::SeqCst);
-    assert!(n > 0);
-    unsafe {
-        let layout = Layout::from_size_align(4, 2).unwrap();
-
-        let memory = Global.allocate(layout.clone()).unwrap();
-        helper::work_with(&memory);
-        assert_eq!(HITS.load(Ordering::SeqCst), n + 1);
-        Global.deallocate(memory.as_non_null_ptr(), layout);
-        assert_eq!(HITS.load(Ordering::SeqCst), n + 2);
-
-        let s = String::with_capacity(10);
-        helper::work_with(&s);
-        assert_eq!(HITS.load(Ordering::SeqCst), n + 3);
-        drop(s);
-        assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
-
-        let memory = System.allocate(layout.clone()).unwrap();
-        helper::work_with(&memory);
-        assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
-        System.deallocate(memory.as_non_null_ptr(), layout);
-        assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
-    }
-}