]> git.lizzy.rs Git - rust.git/blob - src/test/ui/allocator-submodule.rs
Attempt to fix hygiene for global_allocator
[rust.git] / src / test / ui / allocator-submodule.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Tests that it is possible to create a global allocator in a submodule, rather than in the crate
12 // root.
13
14 #![feature(alloc, allocator_api, global_allocator)]
15
16 extern crate alloc;
17
18 use std::alloc::{GlobalAlloc, Layout, Opaque};
19
20 struct MyAlloc;
21
22 unsafe impl GlobalAlloc for MyAlloc {
23     unsafe fn alloc(&self, layout: Layout) -> *mut Opaque {
24         0 as usize as *mut Opaque
25     }
26
27     unsafe fn dealloc(&self, ptr: *mut Opaque, layout: Layout) {}
28 }
29
30 mod submod {
31     use super::MyAlloc;
32
33     #[global_allocator]
34     static MY_HEAP: MyAlloc = MyAlloc;
35 }
36
37 fn main() {}