RegionKind in rustc_middle::ty - Rust
Description: API documentation for the Rust `RegionKind` type in crate `rustc_middle`.

Skip to main content

## RegionKind

# Type Alias RegionKind

Source

    pub type RegionKind<'tcx> = RegionKind<TyCtxt<'tcx>>;

## Aliased Type§

    pub enum RegionKind<'tcx> {
        ReEarlyParam(EarlyParamRegion),
        ReBound(BoundVarIndexKind, BoundRegion<TyCtxt<'tcx>>),
        ReLateParam(LateParamRegion),
        ReStatic,
        ReVar(RegionVid),
        RePlaceholder(Placeholder<TyCtxt<'tcx>, BoundRegion<TyCtxt<'tcx>>>),
        ReErased,
        ReError(ErrorGuaranteed),
    }

## Variants§

§

### ReEarlyParam(EarlyParamRegion)

A region parameter; for example `'a` in `impl<'a> Trait for &'a ()`.

There are some important differences between region and type parameters. Not all region parameters in the source are represented via `ReEarlyParam`: late-bound function parameters are instead lowered to a `ReBound`. Late-bound regions get eagerly replaced with `ReLateParam` which behaves in the same way as `ReEarlyParam`. Region parameters are also sometimes implicit, e.g. in `impl Trait for &()`.

§

### ReBound(BoundVarIndexKind, BoundRegion<TyCtxt<'tcx>>)

A higher-ranked region. These represent either late-bound function parameters or bound variables from a `for<'a>`-binder.

While inside of a function, e.g. during typeck, the late-bound function parameters can be converted to `ReLateParam` by calling `tcx.liberate_late_bound_regions`.

Bound regions inside of types must not be erased, as they impact trait selection and the `TypeId` of that type. `for<'a> fn(&'a ())` and `fn(&'static ())` are different types and have to be treated as such.

§

### ReLateParam(LateParamRegion)

Late-bound function parameters are represented using a `ReBound`. When inside of a function, we convert these bound variables to placeholder parameters via `tcx.liberate_late_bound_regions`. They are then treated the same way as `ReEarlyParam` while inside of the function.

See https://rustc-dev-guide.rust-lang.org/early_late_parameters.html for more info about early and late bound lifetime parameters.

§

### ReStatic

Static data that has an “infinite” lifetime. Bottom in the region lattice.

§

### ReVar(RegionVid)

A region variable. Should not exist outside of type inference.

§

### RePlaceholder(Placeholder<TyCtxt<'tcx>, BoundRegion<TyCtxt<'tcx>>>)

A placeholder region – the higher-ranked version of `ReLateParam`. Should not exist outside of type inference.

Used when instantiating a `forall` binder via `infcx.enter_forall`.

§

### ReErased

Erased region, used by trait selection, in MIR and during codegen.

§

### ReError(ErrorGuaranteed)

A region that resulted from some other error. Used exclusively for diagnostics.

## Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.