]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_ast/src/expand/allocator.rs
Auto merge of #86454 - tlyu:refactor-unsized-suggestions, r=davidtwco
[rust.git] / compiler / rustc_ast / src / expand / allocator.rs
1 use rustc_span::symbol::{sym, Symbol};
2
3 #[derive(Clone, Debug, Copy, HashStable_Generic)]
4 pub enum AllocatorKind {
5     Global,
6     Default,
7 }
8
9 impl AllocatorKind {
10     pub fn fn_name(&self, base: Symbol) -> String {
11         match *self {
12             AllocatorKind::Global => format!("__rg_{}", base),
13             AllocatorKind::Default => format!("__rdl_{}", base),
14         }
15     }
16 }
17
18 pub enum AllocatorTy {
19     Layout,
20     Ptr,
21     ResultPtr,
22     Unit,
23     Usize,
24 }
25
26 pub struct AllocatorMethod {
27     pub name: Symbol,
28     pub inputs: &'static [AllocatorTy],
29     pub output: AllocatorTy,
30 }
31
32 pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
33     AllocatorMethod {
34         name: sym::alloc,
35         inputs: &[AllocatorTy::Layout],
36         output: AllocatorTy::ResultPtr,
37     },
38     AllocatorMethod {
39         name: sym::dealloc,
40         inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout],
41         output: AllocatorTy::Unit,
42     },
43     AllocatorMethod {
44         name: sym::realloc,
45         inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout, AllocatorTy::Usize],
46         output: AllocatorTy::ResultPtr,
47     },
48     AllocatorMethod {
49         name: sym::alloc_zeroed,
50         inputs: &[AllocatorTy::Layout],
51         output: AllocatorTy::ResultPtr,
52     },
53 ];