File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ //! Helper for 'no-allocation-before-main'.
2
+ //!
3
+ //! This also contains a meta-test to make sure that the AbortingAllocator does indeed abort.
4
+ //!
5
+ //! -Cprefer-dynamic=no is required as otherwise #[global_allocator] does nothing.
6
+ //@ run-fail
7
+ //@ compile-flags: -Cprefer-dynamic=no
8
+
9
+ pub struct AbortingAllocator ;
10
+
11
+ unsafe impl std:: alloc:: GlobalAlloc for AbortingAllocator {
12
+ unsafe fn alloc ( & self , _: std:: alloc:: Layout ) -> * mut u8 {
13
+ std:: process:: abort ( )
14
+ }
15
+
16
+ unsafe fn dealloc ( & self , _: * mut u8 , _: std:: alloc:: Layout ) {
17
+ std:: process:: abort ( )
18
+ }
19
+ }
20
+
21
+ #[ global_allocator]
22
+ static ALLOCATOR : AbortingAllocator = AbortingAllocator ;
23
+
24
+ fn main ( ) {
25
+ std:: hint:: black_box ( String :: from ( "An allocation" ) ) ;
26
+ }
Original file line number Diff line number Diff line change
1
+ //! Tests that a program with no body does not allocate.
2
+ //!
3
+ //! The initial runtime should not allocate for performance/binary size reasons.
4
+ //!
5
+ //! -Cprefer-dynamic=no is required as otherwise #[global_allocator] does nothing.
6
+ //@ run-pass
7
+ //@ compile-flags: -Cprefer-dynamic=no
8
+
9
+ #[ allow( dead_code) ]
10
+ #[ path = "aborting-alloc.rs" ]
11
+ mod aux;
12
+
13
+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments