Node in rustc_hir::hir - Rust
Description: API documentation for the Rust `Node` enum in crate `rustc_hir`.

Skip to main content

## Node

# Enum Node

Source

    pub enum Node<'hir> {
    Show 35 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),
        ConstArg(&'hir ConstArg<'hir>),
        Expr(&'hir Expr<'hir>),
        ExprField(&'hir ExprField<'hir>),
        ConstArgExprField(&'hir ConstArgExprField<'hir>),
        Stmt(&'hir Stmt<'hir>),
        PathSegment(&'hir PathSegment<'hir>),
        Ty(&'hir Ty<'hir>),
        AssocItemConstraint(&'hir AssocItemConstraint<'hir>),
        TraitRef(&'hir TraitRef<'hir>),
        OpaqueTy(&'hir OpaqueTy<'hir>),
        TyPat(&'hir TyPat<'hir>),
        Pat(&'hir Pat<'hir>),
        PatField(&'hir PatField<'hir>),
        PatExpr(&'hir PatExpr<'hir>),
        Arm(&'hir Arm<'hir>),
        Block(&'hir Block<'hir>),
        LetStmt(&'hir LetStmt<'hir>),
        Ctor(&'hir VariantData<'hir>),
        Lifetime(&'hir Lifetime),
        GenericParam(&'hir GenericParam<'hir>),
        Crate(&'hir Mod<'hir>),
        Infer(&'hir InferArg),
        WherePredicate(&'hir WherePredicate<'hir>),
        PreciseCapturingNonLifetimeArg(&'hir PreciseCapturingNonLifetimeArg),
        Synthetic,
        Err(Span),
    }

## 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)

§

### ConstArg(&'hir ConstArg<'hir>)

§

### Expr(&'hir Expr<'hir>)

§

### ExprField(&'hir ExprField<'hir>)

§

### ConstArgExprField(&'hir ConstArgExprField<'hir>)

§

### Stmt(&'hir Stmt<'hir>)

§

### PathSegment(&'hir PathSegment<'hir>)

§

### Ty(&'hir Ty<'hir>)

§

### AssocItemConstraint(&'hir AssocItemConstraint<'hir>)

§

### TraitRef(&'hir TraitRef<'hir>)

§

### OpaqueTy(&'hir OpaqueTy<'hir>)

§

### TyPat(&'hir TyPat<'hir>)

§

### Pat(&'hir Pat<'hir>)

§

### PatField(&'hir PatField<'hir>)

§

### PatExpr(&'hir PatExpr<'hir>)

Needed as its own node with its own HirId for tracking the unadjusted type of literals within patterns (e.g. byte str literals not being of slice type).

§

### Arm(&'hir Arm<'hir>)

§

### Block(&'hir Block<'hir>)

§

### LetStmt(&'hir LetStmt<'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)

§

### WherePredicate(&'hir WherePredicate<'hir>)

§

### PreciseCapturingNonLifetimeArg(&'hir PreciseCapturingNonLifetimeArg)

§

### Synthetic

§

### Err(Span)

## 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 `Ctor`s do not have identifiers themselves. Instead, call `.ident()` on the parent struct/variant, like so:

ⓘ

    ctor
        .ctor_hir_id()
        .map(|ctor_id| tcx.parent_hir_node(ctor_id))
        .and_then(|parent| parent.ident())

Source

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

Source

#### pub fn impl_block_of_trait( self, trait_def_id: DefId, ) -> Option<&'hir Impl<'hir>>

Get a `hir::Impl` if the node is an impl block for the given `trait_def_id`.

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 associated_body(&self) -> Option<(LocalDefId, BodyId)>

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 expect_param(&self) -> &'hir Param<'hir>

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

#### pub fn expect_assoc_item_constraint(&self) -> &'hir AssocItemConstraint<'hir>

Source

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

Source

#### pub fn expect_opaque_ty(&self) -> &'hir OpaqueTy<'hir>

Source

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

Source

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

Source

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

Source

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

Source

#### pub fn expect_let_stmt(&self) -> &'hir LetStmt<'hir>

Source

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

Source

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

Source

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

Source

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

Source

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

Source

#### pub fn expect_closure(&self) -> &'hir Closure<'hir>

## Trait Implementations§

Source§

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

Source§

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

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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> From<OwnerNode<'hir>> for Node<'hir>

Source§

#### fn from(val: OwnerNode<'hir>) -> Self

Converts to this type from the input type.
Source§

### impl<'hir> StableHash for Node<'hir>

Source§

#### fn stable_hash<__Hcx: StableHashCtxt>( &self, __hcx: &mut __Hcx, __hasher: &mut StableHasher, )

Source§

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

## Auto Trait Implementations§

§

### impl<'hir> DynSend for Node<'hir>

§

### impl<'hir> DynSync for Node<'hir>

§

### impl<'hir> Freeze for Node<'hir>

§

### 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> UnsafeUnpin for Node<'hir>

§

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

## Blanket Implementations§

Source§

### impl<T> Aligned for T

Source§

#### const ALIGN: Alignment

Alignment of `Self`.
Source§

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

Source§

#### fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more
Source§

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

Source§

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

Source§

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

Source§

### impl<T> Borrow<T> for T
where T: ?Sized,

Source§

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

### impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

### impl<T> CloneToUninit for T
where T: Clone,

Source§

#### unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (`clone_to_uninit`)
Performs copy-assignment from `self` to `dest`. Read more
Source§

### impl<T> DynClone for T
where T: Clone,

Source§

#### fn __clone_box(&self, _: Private) -> *mut ()

Source§

### impl<T> From<T> for T

Source§

#### fn from(t: T) -> T

Returns the argument unchanged.

Source§

### impl<T> Instrument for T

Source§

#### fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided `Span`, returning an `Instrumented` wrapper. Read more
Source§

#### fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current `Span`, returning an `Instrumented` wrapper. Read more
Source§

### impl<T, U> Into<U> for T
where 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> IntoEither for T

Source§

#### fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts `self` into a `Left` variant of `Either<Self, Self>` if `into_left` is `true`. Converts `self` into a `Right` variant of `Either<Self, Self>` otherwise. Read more
Source§

#### fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts `self` into a `Left` variant of `Either<Self, Self>` if `into_left(&self)` returns `true`. Converts `self` into a `Right` variant of `Either<Self, Self>` otherwise. Read more
Source§

### impl<T> Pointable for T

Source§

#### const ALIGN: usize

The alignment of pointer.
Source§

#### type Init = T

The type for initializers.
Source§

#### unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

#### unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

#### unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

#### unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

### impl<T> Same for T

Source§

#### type Output = T

Should always be `Self`
Source§

### impl<T> ToOwned for T
where T: Clone,

Source§

#### 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 T
where U: Into<T>,

Source§

#### 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 T
where U: TryFrom<T>,

Source§

#### 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.
Source§

### impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

#### fn vzip(self) -> V

Source§

### impl<T> WithSubscriber for T

Source§

#### fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided `Subscriber` to this type, returning a `WithDispatch` wrapper. Read more
Source§

#### fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default `Subscriber` to this type, returning a `WithDispatch` wrapper. Read more
Source§

### impl<T> ErasedDestructor for T
where T: 'static,

## 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`: 12 bytes
- `Item`: 12 bytes
- `ForeignItem`: 12 bytes
- `TraitItem`: 12 bytes
- `ImplItem`: 12 bytes
- `Variant`: 12 bytes
- `Field`: 12 bytes
- `AnonConst`: 12 bytes
- `ConstBlock`: 12 bytes
- `ConstArg`: 12 bytes
- `Expr`: 12 bytes
- `ExprField`: 12 bytes
- `ConstArgExprField`: 12 bytes
- `Stmt`: 12 bytes
- `PathSegment`: 12 bytes
- `Ty`: 12 bytes
- `AssocItemConstraint`: 12 bytes
- `TraitRef`: 12 bytes
- `OpaqueTy`: 12 bytes
- `TyPat`: 12 bytes
- `Pat`: 12 bytes
- `PatField`: 12 bytes
- `PatExpr`: 12 bytes
- `Arm`: 12 bytes
- `Block`: 12 bytes
- `LetStmt`: 12 bytes
- `Ctor`: 12 bytes
- `Lifetime`: 12 bytes
- `GenericParam`: 12 bytes
- `Crate`: 12 bytes
- `Infer`: 12 bytes
- `WherePredicate`: 12 bytes
- `PreciseCapturingNonLifetimeArg`: 12 bytes
- `Synthetic`: 0 bytes
- `Err`: 8 bytes