Enum rustc_hir::hir::Node

source ·
pub enum Node<'hir> {
Show 26 variants Param(&'hir Param<'hir>), Item(&'hir Item<'hir>), ForeignItem(&'hir ForeignItem<'hir>), TraitItem(&'hir TraitItem<'hir>), ImplItem(&'hir ImplItem<'hir>), Variant(&'hir Variant<'hir>), Field(&'hir FieldDef<'hir>), AnonConst(&'hir AnonConst), ConstBlock(&'hir ConstBlock), Expr(&'hir Expr<'hir>), ExprField(&'hir ExprField<'hir>), Stmt(&'hir Stmt<'hir>), PathSegment(&'hir PathSegment<'hir>), Ty(&'hir Ty<'hir>), TypeBinding(&'hir TypeBinding<'hir>), TraitRef(&'hir TraitRef<'hir>), Pat(&'hir Pat<'hir>), PatField(&'hir PatField<'hir>), Arm(&'hir Arm<'hir>), Block(&'hir Block<'hir>), Local(&'hir Local<'hir>), Ctor(&'hir VariantData<'hir>), Lifetime(&'hir Lifetime), GenericParam(&'hir GenericParam<'hir>), Crate(&'hir Mod<'hir>), Infer(&'hir InferArg),
}

Variants§

§

Param(&'hir Param<'hir>)

§

Item(&'hir Item<'hir>)

§

ForeignItem(&'hir ForeignItem<'hir>)

§

TraitItem(&'hir TraitItem<'hir>)

§

ImplItem(&'hir ImplItem<'hir>)

§

Variant(&'hir Variant<'hir>)

§

Field(&'hir FieldDef<'hir>)

§

AnonConst(&'hir AnonConst)

§

ConstBlock(&'hir ConstBlock)

§

Expr(&'hir Expr<'hir>)

§

ExprField(&'hir ExprField<'hir>)

§

Stmt(&'hir Stmt<'hir>)

§

PathSegment(&'hir PathSegment<'hir>)

§

Ty(&'hir Ty<'hir>)

§

TypeBinding(&'hir TypeBinding<'hir>)

§

TraitRef(&'hir TraitRef<'hir>)

§

Pat(&'hir Pat<'hir>)

§

PatField(&'hir PatField<'hir>)

§

Arm(&'hir Arm<'hir>)

§

Block(&'hir Block<'hir>)

§

Local(&'hir Local<'hir>)

§

Ctor(&'hir VariantData<'hir>)

Ctor refers to the constructor of an enum variant or struct. Only tuple or unit variants with synthesized constructors.

§

Lifetime(&'hir Lifetime)

§

GenericParam(&'hir GenericParam<'hir>)

§

Crate(&'hir Mod<'hir>)

§

Infer(&'hir InferArg)

Implementations§

source§

impl<'hir> Node<'hir>

source

pub fn ident(&self) -> Option<Ident>

Get the identifier of this Node, if applicable.

Edge cases

Calling .ident() on a Node::Ctor will return None because Ctors do not have identifiers themselves. Instead, call .ident() on the parent struct/variant, like so:

ctor
    .ctor_hir_id()
    .and_then(|ctor_id| tcx.hir().find_parent(ctor_id))
    .and_then(|parent| parent.ident())
source

pub fn fn_decl(self) -> Option<&'hir FnDecl<'hir>>

source

pub fn fn_sig(self) -> Option<&'hir FnSig<'hir>>

source

pub fn ty(self) -> Option<&'hir Ty<'hir>>

Get the type for constants, assoc types, type aliases and statics.

source

pub fn alias_ty(self) -> Option<&'hir Ty<'hir>>

source

pub fn body_id(&self) -> Option<BodyId>

source

pub fn generics(self) -> Option<&'hir Generics<'hir>>

source

pub fn as_owner(self) -> Option<OwnerNode<'hir>>

source

pub fn fn_kind(self) -> Option<FnKind<'hir>>

source

pub fn tuple_fields(&self) -> Option<&'hir [FieldDef<'hir>]>

Get the fields for the tuple-constructor, if this node is a tuple constructor, otherwise None

source

pub fn expect_param(self) -> &'hir Param<'hir>

Expect a Node::Param or panic.

source

pub fn expect_item(self) -> &'hir Item<'hir>

Expect a Node::Item or panic.

source

pub fn expect_foreign_item(self) -> &'hir ForeignItem<'hir>

Expect a Node::ForeignItem or panic.

source

pub fn expect_trait_item(self) -> &'hir TraitItem<'hir>

Expect a Node::TraitItem or panic.

source

pub fn expect_impl_item(self) -> &'hir ImplItem<'hir>

Expect a Node::ImplItem or panic.

source

pub fn expect_variant(self) -> &'hir Variant<'hir>

Expect a Node::Variant or panic.

source

pub fn expect_field(self) -> &'hir FieldDef<'hir>

Expect a Node::Field or panic.

source

pub fn expect_anon_const(self) -> &'hir AnonConst

Expect a Node::AnonConst or panic.

source

pub fn expect_inline_const(self) -> &'hir ConstBlock

Expect a Node::ConstBlock or panic.

source

pub fn expect_expr(self) -> &'hir Expr<'hir>

Expect a Node::Expr or panic.

source

pub fn expect_expr_field(self) -> &'hir ExprField<'hir>

Expect a Node::ExprField or panic.

source

pub fn expect_stmt(self) -> &'hir Stmt<'hir>

Expect a Node::Stmt or panic.

source

pub fn expect_path_segment(self) -> &'hir PathSegment<'hir>

Expect a Node::PathSegment or panic.

source

pub fn expect_ty(self) -> &'hir Ty<'hir>

Expect a Node::Ty or panic.

source

pub fn expect_type_binding(self) -> &'hir TypeBinding<'hir>

Expect a Node::TypeBinding or panic.

source

pub fn expect_trait_ref(self) -> &'hir TraitRef<'hir>

Expect a Node::TraitRef or panic.

source

pub fn expect_pat(self) -> &'hir Pat<'hir>

Expect a Node::Pat or panic.

source

pub fn expect_pat_field(self) -> &'hir PatField<'hir>

Expect a Node::PatField or panic.

source

pub fn expect_arm(self) -> &'hir Arm<'hir>

Expect a Node::Arm or panic.

source

pub fn expect_block(self) -> &'hir Block<'hir>

Expect a Node::Block or panic.

source

pub fn expect_local(self) -> &'hir Local<'hir>

Expect a Node::Local or panic.

source

pub fn expect_ctor(self) -> &'hir VariantData<'hir>

Expect a Node::Ctor or panic.

source

pub fn expect_lifetime(self) -> &'hir Lifetime

Expect a Node::Lifetime or panic.

source

pub fn expect_generic_param(self) -> &'hir GenericParam<'hir>

Expect a Node::GenericParam or panic.

source

pub fn expect_crate(self) -> &'hir Mod<'hir>

Expect a Node::Crate or panic.

source

pub fn expect_infer(self) -> &'hir InferArg

Expect a Node::Infer or panic.

source

fn expect_failed(&self, expected: &'static str) -> !

Trait Implementations§

source§

impl<'hir> Clone for Node<'hir>

source§

fn clone(&self) -> Node<'hir>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'hir> Debug for Node<'hir>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'hir, __CTX> HashStable<__CTX> for Node<'hir>where __CTX: HashStableContext,

source§

fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)

source§

impl<'hir> Into<Node<'hir>> for OwnerNode<'hir>

source§

fn into(self) -> Node<'hir>

Converts this type into the (usually inferred) input type.
source§

impl<'hir> Copy for Node<'hir>

Auto Trait Implementations§

§

impl<'hir> !RefUnwindSafe for Node<'hir>

§

impl<'hir> !Send for Node<'hir>

§

impl<'hir> !Sync for Node<'hir>

§

impl<'hir> Unpin for Node<'hir>

§

impl<'hir> !UnwindSafe for Node<'hir>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere T: Copy,

source§

fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut T

source§

fn allocate_from_iter<'a>( arena: &'a Arena<'tcx>, iter: impl IntoIterator<Item = T> ) -> &'a mut [T]

source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 16 bytes

Size for each variant:

  • Param: 8 bytes
  • Item: 8 bytes
  • ForeignItem: 8 bytes
  • TraitItem: 8 bytes
  • ImplItem: 8 bytes
  • Variant: 8 bytes
  • Field: 8 bytes
  • AnonConst: 8 bytes
  • ConstBlock: 8 bytes
  • Expr: 8 bytes
  • ExprField: 8 bytes
  • Stmt: 8 bytes
  • PathSegment: 8 bytes
  • Ty: 8 bytes
  • TypeBinding: 8 bytes
  • TraitRef: 8 bytes
  • Pat: 8 bytes
  • PatField: 8 bytes
  • Arm: 8 bytes
  • Block: 8 bytes
  • Local: 8 bytes
  • Ctor: 8 bytes
  • Lifetime: 8 bytes
  • GenericParam: 8 bytes
  • Crate: 8 bytes
  • Infer: 8 bytes