rustc_hir/
lib.rs

1//! HIR datatypes. See the [rustc dev guide] for more info.
2//!
3//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
4
5// tidy-alphabetical-start
6#![feature(associated_type_defaults)]
7#![feature(closure_track_caller)]
8#![feature(const_default)]
9#![feature(const_trait_impl)]
10#![feature(derive_const)]
11#![feature(exhaustive_patterns)]
12#![feature(never_type)]
13#![feature(variant_count)]
14#![recursion_limit = "256"]
15// tidy-alphabetical-end
16
17extern crate self as rustc_hir;
18
19mod arena;
20pub mod attrs;
21pub mod def;
22pub mod def_path_hash_map;
23pub mod definitions;
24pub mod diagnostic_items;
25pub use rustc_span::def_id;
26mod hir;
27pub use rustc_hir_id::{self as hir_id, *};
28pub mod intravisit;
29pub mod lang_items;
30pub mod limit;
31pub mod lints;
32pub mod pat_util;
33mod stability;
34mod stable_hash_impls;
35pub mod target;
36pub mod weak_lang_items;
37
38#[cfg(test)]
39mod tests;
40
41#[doc(no_inline)]
42pub use hir::*;
43pub use lang_items::{LangItem, LanguageItems};
44pub use rustc_ast::attr::version::*;
45pub use stability::*;
46pub use stable_hash_impls::HashStableContext;
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);