# Enum rustc_hir::def::DefKind

source ·

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

Expand description

What kind of definition something is; e.g., `mod` vs `struct`. `enum DefPathData` may need to be updated if a new variant is added here.

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

#### Fields

§`safety: Safety`

Whether it’s a `unsafe static`, `safe static` (inside extern only) or just a `static`.

§`mutability: Mutability`

Whether it’s a `static mut` or just a `static`.

§`nested: bool`

Whether it’s an anonymous static generated for nested allocations.

§

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

A field in a struct, enum or union. e.g.

- `bar` in `struct Foo { bar: u8 }`
- `Foo::Bar::0` in `enum Foo { Bar(u8) }`

§

### LifetimeParam

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

§

### GlobalAsm

A use of `global_asm!`.

§

### Impl

#### Fields

§`of_trait: bool`
§

### Closure

A closure, coroutine, or coroutine-closure.

These are all represented with the same `ExprKind::Closure` in the AST and HIR, which makes it difficult to distinguish these during def collection. Therefore, we treat them all the same, and code which needs to distinguish them can match or `hir::ClosureKind` or `type_of`.

## 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 coroutines 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 coroutines and associated functions.

source

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

source

#### pub fn def_path_data(self, name: Symbol) -> DefPathData

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: SpanDecoder> Decodable<__D> for DefKind

source§

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

source§

### impl<__E: SpanEncoder> 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 DefKind
where __CTX: HashStableContext,

source§

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

source§

### impl PartialEq 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 StructuralPartialEq for DefKind

## Auto Trait Implementations§

§

### impl DynSend for DefKind

§

### impl DynSync for DefKind

§

### impl Freeze for DefKind

§

### impl RefUnwindSafe for DefKind

§

### impl Send for DefKind

§

### impl Sync for DefKind

§

### impl Unpin for DefKind

§

### impl UnwindSafe for DefKind

## 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<'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 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: Copy,

source§

#### unsafe fn clone_to_uninit(&self, dst: *mut T)

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

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

source§

#### default unsafe fn clone_to_uninit(&self, dst: *mut T)

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

### impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

#### fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

### impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

#### fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

### impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

#### fn equivalent(&self, key: &K) -> bool

Compare self to `key` and return `true` if they are equal.
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.
§

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

§

#### type Output = T

Should always be `Self`
source§

### impl<T> ToOwned for T
where 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 T
where 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 T
where 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.
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<'a, T> Captures<'a> for T
where T: ?Sized,

## 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: 3 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`: 3 bytes
- `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