1 use crate::{ast, attr, visit};
2 use syntax_pos::symbol::{sym, Symbol};
6 pub enum AllocatorKind {
13 pub fn fn_name(&self, base: &str) -> String {
15 AllocatorKind::Global => format!("__rg_{}", base),
16 AllocatorKind::DefaultLib => format!("__rdl_{}", base),
17 AllocatorKind::DefaultExe => format!("__rde_{}", base),
22 pub enum AllocatorTy {
30 pub struct AllocatorMethod {
31 pub name: &'static str,
32 pub inputs: &'static [AllocatorTy],
33 pub output: AllocatorTy,
36 pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
39 inputs: &[AllocatorTy::Layout],
40 output: AllocatorTy::ResultPtr,
44 inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout],
45 output: AllocatorTy::Unit,
49 inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout, AllocatorTy::Usize],
50 output: AllocatorTy::ResultPtr,
54 inputs: &[AllocatorTy::Layout],
55 output: AllocatorTy::ResultPtr,
59 pub fn global_allocator_spans(krate: &ast::Crate) -> Vec<Span> {
60 struct Finder { name: Symbol, spans: Vec<Span> }
61 impl<'ast> visit::Visitor<'ast> for Finder {
62 fn visit_item(&mut self, item: &'ast ast::Item) {
63 if item.ident.name == self.name &&
64 attr::contains_name(&item.attrs, sym::rustc_std_internal_symbol) {
65 self.spans.push(item.span);
67 visit::walk_item(self, item)
71 let name = Symbol::intern(&AllocatorKind::Global.fn_name("alloc"));
72 let mut f = Finder { name, spans: Vec::new() };
73 visit::walk_crate(&mut f, krate);