1#![feature(associated_type_defaults)]
7#![feature(closure_track_caller)]
8#![feature(const_default)]
9#![feature(const_trait_impl)]
10#![feature(default_field_values)]
11#![feature(derive_const)]
12#![feature(exhaustive_patterns)]
13#![feature(never_type)]
14#![feature(variant_count)]
15#![recursion_limit = "256"]
16extern crate self as rustc_hir;
19
20mod arena;
21pub mod attrs;
22pub mod def;
23pub mod def_path_hash_map;
24pub mod definitions;
25pub mod diagnostic_items;
26pub use rustc_span::def_id;
27mod hir;
28pub use rustc_hir_id::{self as hir_id, *};
29pub mod intravisit;
30pub mod lang_items;
31pub mod limit;
32pub mod lints;
33pub mod pat_util;
34mod stability;
35mod stable_hash_impls;
36pub mod target;
37pub mod weak_lang_items;
38
39#[cfg(test)]
40mod tests;
41
42#[doc(no_inline)]
43pub use hir::*;
44pub use lang_items::{LangItem, LanguageItems};
45pub use rustc_ast::attr::version::*;
46pub use stability::*;
47pub use target::{MethodKind, Target};
48
49pub struct Arena<'tcx> {
pub dropless: ::rustc_arena::DroplessArena,
asm_template: ::rustc_arena::TypedArena<rustc_ast::InlineAsmTemplatePiece>,
attribute: ::rustc_arena::TypedArena<rustc_hir::Attribute>,
owner_info: ::rustc_arena::TypedArena<rustc_hir::OwnerInfo<'tcx>>,
macro_def: ::rustc_arena::TypedArena<rustc_ast::MacroDef>,
}
#[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(),
}
}
}
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_hir::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
rustc_hir::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> 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)
}
}arena_types!(rustc_arena::declare_arena);