1 // Issue #54478: regression test showing that we can demonstrate
2 // `#[global_allocator]` in code blocks built by `rustdoc`.
6 // Changes in lang-item visibility injected failures that were only
7 // exposed when compiling with `-C prefer-dynamic`. But `rustdoc` used
8 // `-C prefer-dynamic` (and had done so for years, for reasons we did
9 // not document at that time).
11 // Rather than try to revise the visbility semanics, we instead
12 // decided to change `rustdoc` to behave more like the compiler's
13 // default setting, by leaving off `-C prefer-dynamic`.
15 // compile-flags:--test
17 //! This is a doc comment
20 //! use std::alloc::*;
22 //! #[global_allocator]
23 //! static ALLOC: A = A;
25 //! static mut HIT: bool = false;
29 //! unsafe impl GlobalAlloc for A {
30 //! unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
32 //! System.alloc(layout)
34 //! unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
35 //! System.dealloc(ptr, layout);
40 //! assert!(unsafe { HIT });