Value in rustc_middle::queries::def_kind - Rust
Description: API documentation for the Rust `Value` type in crate `rustc_middle`.

Skip to main content

## Value

# Type Alias Value

Source

    pub type Value<'tcx> = DefKind;

## Aliased Type§

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

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

#### Fields

§`is_type_const: bool`
§

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

    struct S;
    let x = S; // S in the value namespace is a Ctor

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; }`

#### Fields

§`is_type_const: bool`
§

### Macro(MacroKinds)

§

### ExternCrate

§

### Use

§

### ForeignMod

An `extern` block.

§

### AnonConst

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

Not all anon-consts are actually still relevant in the HIR. We lower trivial const-arguments directly to `hir::ConstArgKind::Path`, at which point the definition for the anon-const ends up unused and incomplete.

We do not provide any a `Span` for the definition and pretty much all other queries also ICE when using this `DefId`. Given that the `DefId` of such constants should only be reachable by iterating all definitions of a given crate, you should not have to worry about this.

§

### 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 on `hir::ClosureKind` or `type_of`.

§

### SyntheticCoroutineBody

The definition of a synthetic coroutine body created by the lowering of a coroutine-closure, such as an async closure.

## 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`: 2 bytes
- `ConstParam`: 0 bytes
- `Static`: 3 bytes
- `Ctor`: 3 bytes
- `AssocFn`: 0 bytes
- `AssocConst`: 2 bytes
- `Macro`: 2 bytes
- `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`: 2 bytes
- `Closure`: 0 bytes
- `SyntheticCoroutineBody`: 0 bytes