]> git.lizzy.rs Git - rust.git/blob - src/test/ui/allocator-submodule.rs
Rollup merge of #53317 - estebank:abolish-ice, r=oli-obk
[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::{
19     alloc::{GlobalAlloc, Layout},
20     ptr,
21 };
22
23 struct MyAlloc;
24
25 unsafe impl GlobalAlloc for MyAlloc {
26     unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
27         ptr::null_mut()
28     }
29
30     unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {}
31 }
32
33 mod submod {
34     use super::MyAlloc;
35
36     #[global_allocator]
37     static MY_HEAP: MyAlloc = MyAlloc; //~ ERROR global_allocator
38 }
39
40 fn main() {}