Enum rustc_hir::def::DefKind

source ·
pub enum DefKind {
Show 31 variants Mod, Struct, Union, Enum, Variant, Trait, TyAlias, ForeignTy, TraitAlias, AssocTy, TyParam, Fn, Const, ConstParam, Static(Mutability), Ctor(CtorOf, CtorKind), AssocFn, AssocConst, Macro(MacroKind), ExternCrate, Use, ForeignMod, AnonConst, InlineConst, OpaqueTy, Field, LifetimeParam, GlobalAsm, Impl { of_trait: bool, }, Closure, Generator,
}
Expand description

What kind of definition something is; e.g., mod vs struct.

Variants§

§

Mod

§

Struct

Refers to the struct itself, DefKind::Ctor refers to its constructor if it exists.

§

Union

§

Enum

§

Variant

Refers to the variant itself, DefKind::Ctor refers to its constructor if it exists.

§

Trait

§

TyAlias

Type alias: type Foo = Bar;

§

ForeignTy

Type from an extern block.

§

TraitAlias

Trait alias: trait IntIterator = Iterator<Item = i32>;

§

AssocTy

Associated type: trait MyTrait { type Assoc; }

§

TyParam

Type parameter: the T in struct Vec<T> { ... }

§

Fn

§

Const

§

ConstParam

Constant generic parameter: struct Foo<const N: usize> { ... }

§

Static(Mutability)

§

Ctor(CtorOf, CtorKind)

Refers to the struct or enum variant’s constructor.

The reason Ctor exists in addition to DefKind::Struct and DefKind::Variant is because structs and enum variants exist in the type namespace, whereas struct and enum variant constructors exist in the value namespace.

You may wonder why enum variants exist in the type namespace as opposed to the value namespace. Check out RFC 2593 for intuition on why that is.

§

AssocFn

Associated function: impl MyStruct { fn associated() {} } or trait Foo { fn associated() {} }

§

AssocConst

Associated constant: trait MyTrait { const ASSOC: usize; }

§

Macro(MacroKind)

§

ExternCrate

§

Use

§

ForeignMod

An extern block.

§

AnonConst

Anonymous constant, e.g. the 1 + 2 in [u8; 1 + 2]

§

InlineConst

An inline constant, e.g. const { 1 + 2 }

§

OpaqueTy

Opaque type, aka impl Trait.

§

Field

§

LifetimeParam

Lifetime parameter: the 'a in struct Foo<'a> { ... }

§

GlobalAsm

A use of global_asm!.

§

Impl

Fields

§of_trait: bool
§

Closure

§

Generator

Implementations§

source§

impl DefKind

source

pub fn descr(self, def_id: DefId) -> &'static str

Get an English description for the item’s kind.

If you have access to TyCtxt, use TyCtxt::def_descr or TyCtxt::def_kind_descr instead, because they give better information for generators and associated functions.

source

pub fn article(&self) -> &'static str

Gets an English article for the definition.

If you have access to TyCtxt, use TyCtxt::def_descr_article or TyCtxt::def_kind_descr_article instead, because they give better information for generators and associated functions.

source

pub fn ns(&self) -> Option<Namespace>

source

pub fn is_fn_like(self) -> bool

source

pub fn has_codegen_attrs(self) -> bool

Whether query get_codegen_attrs should be used with this definition.

Trait Implementations§

source§

impl Clone for DefKind

source§

fn clone(&self) -> DefKind

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 Debug for DefKind

source§

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

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

impl<__D: Decoder> Decodable<__D> for DefKind

source§

fn decode(__decoder: &mut __D) -> Self

source§

impl<__E: Encoder> Encodable<__E> for DefKind

source§

fn encode(&self, __encoder: &mut __E)

source§

impl Hash for DefKind

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<__CTX> HashStable<__CTX> for DefKindwhere __CTX: HashStableContext,

source§

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

source§

impl PartialEq<DefKind> for DefKind

source§

fn eq(&self, other: &DefKind) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for DefKind

source§

impl Eq for DefKind

source§

impl StructuralEq for DefKind

source§

impl StructuralPartialEq for DefKind

Auto Trait Implementations§

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: 2 bytes

Size for each variant:

  • Mod: 0 bytes
  • Struct: 0 bytes
  • Union: 0 bytes
  • Enum: 0 bytes
  • Variant: 0 bytes
  • Trait: 0 bytes
  • TyAlias: 0 bytes
  • ForeignTy: 0 bytes
  • TraitAlias: 0 bytes
  • AssocTy: 0 bytes
  • TyParam: 0 bytes
  • Fn: 0 bytes
  • Const: 0 bytes
  • ConstParam: 0 bytes
  • Static: 1 byte
  • Ctor: 2 bytes
  • AssocFn: 0 bytes
  • AssocConst: 0 bytes
  • Macro: 1 byte
  • ExternCrate: 0 bytes
  • Use: 0 bytes
  • ForeignMod: 0 bytes
  • AnonConst: 0 bytes
  • InlineConst: 0 bytes
  • OpaqueTy: 0 bytes
  • Field: 0 bytes
  • LifetimeParam: 0 bytes
  • GlobalAsm: 0 bytes
  • Impl: 1 byte
  • Closure: 0 bytes
  • Generator: 0 bytes