File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Issue #54478: regression test showing that we can demonstrate
2
+ // `#[global_allocator]` in code blocks built by `rustdoc`.
3
+ //
4
+ // ## Background
5
+ //
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).
10
+ //
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`.
14
+
15
+ // compile-flags:--test
16
+
17
+ //! This is a doc comment
18
+ //!
19
+ //! ```rust
20
+ //! use std::alloc::*;
21
+ //!
22
+ //! #[global_allocator]
23
+ //! static ALLOC: A = A;
24
+ //!
25
+ //! static mut HIT: bool = false;
26
+ //!
27
+ //! struct A;
28
+ //!
29
+ //! unsafe impl GlobalAlloc for A {
30
+ //! unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
31
+ //! HIT = true;
32
+ //! System.alloc(layout)
33
+ //! }
34
+ //! unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
35
+ //! System.dealloc(ptr, layout);
36
+ //! }
37
+ //! }
38
+ //!
39
+ //! fn main() {
40
+ //! assert!(unsafe { HIT });
41
+ //! }
42
+ //! ```
You can’t perform that action at this time.
0 commit comments