1pub struct Arena<'tcx> {
pub dropless: ::rustc_arena::DroplessArena,
asm_template: ::rustc_arena::TypedArena<rustc_ast::InlineAsmTemplatePiece>,
attribute: ::rustc_arena::TypedArena<rustc_attr_ir::Attribute>,
owner_info: ::rustc_arena::TypedArena<crate::OwnerInfo<'tcx>>,
macro_def: ::rustc_arena::TypedArena<rustc_ast::MacroDef>,
delegation_info: ::rustc_arena::TypedArena<crate::DelegationInfo>,
}
#[automatically_derived]
impl<'tcx> ::core::default::Default for Arena<'tcx> {
#[inline]
fn default() -> Arena<'tcx> {
Arena {
dropless: ::core::default::Default::default(),
asm_template: ::core::default::Default::default(),
attribute: ::core::default::Default::default(),
owner_info: ::core::default::Default::default(),
macro_def: ::core::default::Default::default(),
delegation_info: ::core::default::Default::default(),
}
}
}
pub trait ArenaAllocatable<'tcx, C = rustc_arena::IsNotCopy>: Sized {
#[allow(clippy :: mut_from_ref)]
fn allocate_on(self, arena: &'tcx Arena<'tcx>)
-> &'tcx mut Self;
#[allow(clippy :: mut_from_ref)]
fn allocate_from_iter(arena: &'tcx Arena<'tcx>,
iter: impl ::std::iter::IntoIterator<Item = Self>)
-> &'tcx mut [Self];
}
impl<'tcx, T: Copy> ArenaAllocatable<'tcx, rustc_arena::IsCopy> for T {
#[inline]
#[allow(clippy :: mut_from_ref)]
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut Self {
arena.dropless.alloc(self)
}
#[inline]
#[allow(clippy :: mut_from_ref)]
fn allocate_from_iter(arena: &'tcx Arena<'tcx>,
iter: impl ::std::iter::IntoIterator<Item = Self>)
-> &'tcx mut [Self] {
arena.dropless.alloc_from_iter(iter)
}
}
impl<'tcx> ArenaAllocatable<'tcx, rustc_arena::IsNotCopy> for
rustc_ast::InlineAsmTemplatePiece {
#[inline]
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut Self {
if !::std::mem::needs_drop::<Self>() {
arena.dropless.alloc(self)
} else { arena.asm_template.alloc(self) }
}
#[inline]
#[allow(clippy :: mut_from_ref)]
fn allocate_from_iter(arena: &'tcx Arena<'tcx>,
iter: impl ::std::iter::IntoIterator<Item = Self>)
-> &'tcx mut [Self] {
if !::std::mem::needs_drop::<Self>() {
arena.dropless.alloc_from_iter(iter)
} else { arena.asm_template.alloc_from_iter(iter) }
}
}
impl<'tcx> ArenaAllocatable<'tcx, rustc_arena::IsNotCopy> for
rustc_attr_ir::Attribute {
#[inline]
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut Self {
if !::std::mem::needs_drop::<Self>() {
arena.dropless.alloc(self)
} else { arena.attribute.alloc(self) }
}
#[inline]
#[allow(clippy :: mut_from_ref)]
fn allocate_from_iter(arena: &'tcx Arena<'tcx>,
iter: impl ::std::iter::IntoIterator<Item = Self>)
-> &'tcx mut [Self] {
if !::std::mem::needs_drop::<Self>() {
arena.dropless.alloc_from_iter(iter)
} else { arena.attribute.alloc_from_iter(iter) }
}
}
impl<'tcx> ArenaAllocatable<'tcx, rustc_arena::IsNotCopy> for
crate::OwnerInfo<'tcx> {
#[inline]
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut Self {
if !::std::mem::needs_drop::<Self>() {
arena.dropless.alloc(self)
} else { arena.owner_info.alloc(self) }
}
#[inline]
#[allow(clippy :: mut_from_ref)]
fn allocate_from_iter(arena: &'tcx Arena<'tcx>,
iter: impl ::std::iter::IntoIterator<Item = Self>)
-> &'tcx mut [Self] {
if !::std::mem::needs_drop::<Self>() {
arena.dropless.alloc_from_iter(iter)
} else { arena.owner_info.alloc_from_iter(iter) }
}
}
impl<'tcx> ArenaAllocatable<'tcx, rustc_arena::IsNotCopy> for
rustc_ast::MacroDef {
#[inline]
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut Self {
if !::std::mem::needs_drop::<Self>() {
arena.dropless.alloc(self)
} else { arena.macro_def.alloc(self) }
}
#[inline]
#[allow(clippy :: mut_from_ref)]
fn allocate_from_iter(arena: &'tcx Arena<'tcx>,
iter: impl ::std::iter::IntoIterator<Item = Self>)
-> &'tcx mut [Self] {
if !::std::mem::needs_drop::<Self>() {
arena.dropless.alloc_from_iter(iter)
} else { arena.macro_def.alloc_from_iter(iter) }
}
}
impl<'tcx> ArenaAllocatable<'tcx, rustc_arena::IsNotCopy> for
crate::DelegationInfo {
#[inline]
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut Self {
if !::std::mem::needs_drop::<Self>() {
arena.dropless.alloc(self)
} else { arena.delegation_info.alloc(self) }
}
#[inline]
#[allow(clippy :: mut_from_ref)]
fn allocate_from_iter(arena: &'tcx Arena<'tcx>,
iter: impl ::std::iter::IntoIterator<Item = Self>)
-> &'tcx mut [Self] {
if !::std::mem::needs_drop::<Self>() {
arena.dropless.alloc_from_iter(iter)
} else { arena.delegation_info.alloc_from_iter(iter) }
}
}
impl<'tcx> Arena<'tcx> {
#[inline]
#[allow(clippy :: mut_from_ref)]
pub fn alloc<T: ArenaAllocatable<'tcx, C>, C>(&'tcx self, value: T)
-> &mut T {
value.allocate_on(self)
}
#[inline]
#[allow(clippy :: mut_from_ref)]
pub fn alloc_slice<T: ::std::marker::Copy>(&self, value: &[T])
-> &mut [T] {
if value.is_empty() { return &mut []; }
self.dropless.alloc_slice(value)
}
#[inline]
pub fn alloc_str(&self, string: &str) -> &str {
if string.is_empty() { return ""; }
self.dropless.alloc_str(string)
}
#[allow(clippy :: mut_from_ref)]
pub fn alloc_from_iter<T: ArenaAllocatable<'tcx, C>,
C>(&'tcx self, iter: impl ::std::iter::IntoIterator<Item = T>)
-> &mut [T] {
T::allocate_from_iter(self, iter)
}
}rustc_arena::declare_arena! {
5 asm_template: rustc_ast::InlineAsmTemplatePiece,
7 attribute: rustc_attr_ir::Attribute,
8 owner_info: crate::OwnerInfo<'tcx>,
9 macro_def: rustc_ast::MacroDef,
10 delegation_info: crate::DelegationInfo,
11}