1 use crate::{ast, attr, visit};
2 use rustc_span::symbol::{sym, Symbol};
6 pub enum AllocatorKind {
12 pub fn fn_name(&self, base: Symbol) -> String {
14 AllocatorKind::Global => format!("__rg_{}", base),
15 AllocatorKind::Default => format!("__rdl_{}", base),
20 pub enum AllocatorTy {
28 pub struct AllocatorMethod {
30 pub inputs: &'static [AllocatorTy],
31 pub output: AllocatorTy,
34 pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
37 inputs: &[AllocatorTy::Layout],
38 output: AllocatorTy::ResultPtr,
42 inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout],
43 output: AllocatorTy::Unit,
47 inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout, AllocatorTy::Usize],
48 output: AllocatorTy::ResultPtr,
51 name: sym::alloc_zeroed,
52 inputs: &[AllocatorTy::Layout],
53 output: AllocatorTy::ResultPtr,
57 pub fn global_allocator_spans(krate: &ast::Crate) -> Vec<Span> {
62 impl<'ast> visit::Visitor<'ast> for Finder {
63 fn visit_item(&mut self, item: &'ast ast::Item) {
64 if item.ident.name == self.name
65 && attr::contains_name(&item.attrs, sym::rustc_std_internal_symbol)
67 self.spans.push(item.span);
69 visit::walk_item(self, item)
73 let name = Symbol::intern(&AllocatorKind::Global.fn_name(sym::alloc));
74 let mut f = Finder { name, spans: Vec::new() };
75 visit::walk_crate(&mut f, krate);