[][src]Enum rustc::ty::RegionKind

pub enum RegionKind {
    ReEarlyBound(EarlyBoundRegion),
    ReLateBound(DebruijnIndexBoundRegion),
    ReFree(FreeRegion),
    ReScope(Scope),
    ReStatic,
    ReVar(RegionVid),
    RePlaceholder(PlaceholderRegion),
    ReEmpty,
    ReErased,
    ReClosureBound(RegionVid),
}
⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

Representation of regions.

Unlike types, most region variants are "fictitious", not concrete, regions. Among these, ReStatic, ReEmpty and ReScope are the only ones representing concrete regions.

Bound Regions

These are regions that are stored behind a binder and must be substituted with some concrete region before being used. There are two kind of bound regions: early-bound, which are bound in an item's Generics, and are substituted by a InternalSubsts, and late-bound, which are part of higher-ranked types (e.g., for<'a> fn(&'a ())), and are substituted by the likes of liberate_late_bound_regions. The distinction exists because higher-ranked lifetimes aren't supported in all places. See 1.

Unlike Params, bound regions are not supposed to exist "in the wild" outside their binder, e.g., in types passed to type inference, and should first be substituted (by placeholder regions, free regions, or region variables).

Placeholder and Free Regions

One often wants to work with bound regions without knowing their precise identity. For example, when checking a function, the lifetime of a borrow can end up being assigned to some region parameter. In these cases, it must be ensured that bounds on the region can't be accidentally assumed without being checked.

To do this, we replace the bound regions with placeholder markers, which don't satisfy any relation not explicitly provided.

There are two kinds of placeholder regions in rustc: ReFree and RePlaceholder. When checking an item's body, ReFree is supposed to be used. These also support explicit bounds: both the internally-stored scope, which the region is assumed to outlive, as well as other relations stored in the FreeRegionMap. Note that these relations aren't checked when you make_subregion (or eq_types), only by resolve_regions_and_report_errors.

When working with higher-ranked types, some region relations aren't yet known, so you can't just call resolve_regions_and_report_errors. RePlaceholder is designed for this purpose. In these contexts, there's also the risk that some inference variable laying around will get unified with your placeholder region: if you want to check whether for<'a> Foo<'_>: 'a, and you substitute your bound region 'a with a placeholder region '%a, the variable '_ would just be instantiated to the placeholder region '%a, which is wrong because the inference variable is supposed to satisfy the relation for every value of the placeholder region. To ensure that doesn't happen, you can use leak_check. This is more clearly explained by the rustc guide.

Variants

ReEarlyBound(EarlyBoundRegion)
⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

Region bound in a type or fn declaration which will be substituted 'early' -- that is, at the same time when type parameters are substituted.

ReLateBound(DebruijnIndexBoundRegion)
⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

Region bound in a function scope, which will be substituted when the function is called.

ReFree(FreeRegion)
⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

When checking a function body, the types of all arguments and so forth that refer to bound region parameters are modified to refer to free region parameters.

ReScope(Scope)
⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

A concrete region naming some statically determined scope (e.g., an expression or sequence of statements) within the current function.

ReStatic
⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

Static data that has an "infinite" lifetime. Top in the region lattice.

ReVar(RegionVid)
⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

A region variable. Should not exist after typeck.

RePlaceholder(PlaceholderRegion)
⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

A placeholder region -- basically, the higher-ranked version of ReFree. Should not exist after typeck.

ReEmpty
⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

Empty lifetime is for data that is never accessed. Bottom in the region lattice. We treat ReEmpty somewhat specially; at least right now, we do not generate instances of it during the GLB computations, but rather generate an error instead. This is to improve error messages. The only way to get an instance of ReEmpty is to have a region variable with no constraints.

ReErased
⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

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

ReClosureBound(RegionVid)
⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

These are regions bound in the "defining type" for a closure. They are used ONLY as part of the ClosureRegionRequirements that are produced by MIR borrowck. See ClosureRegionRequirements for more details.

Methods

impl RegionKind[src]

Region utilities

pub fn has_name(&self) -> bool[src]

⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

Is this region named by the user?

pub fn is_late_bound(&self) -> bool[src]

⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

pub fn is_placeholder(&self) -> bool[src]

⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

pub fn bound_at_or_above_binder(&self, index: DebruijnIndex) -> bool[src]

⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

pub fn shifted_out_to_binder(&self, to_binder: DebruijnIndex) -> RegionKind[src]

⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

Adjusts any De Bruijn indices so as to make to_binder the innermost binder. That is, if we have something bound at to_binder, it will now be bound at INNERMOST. This is an appropriate thing to do when moving a region out from inside binders:

            for<'a>   fn(for<'b>   for<'c>   fn(&'a u32), _)
// Binder:  D3           D2        D1            ^^

Here, the region 'a would have the De Bruijn index D3, because it is the bound 3 binders out. However, if we wanted to refer to that region 'a in the second argument (the _), those two binders would not be in scope. In that case, we might invoke shift_out_to_binder(D3). This would adjust the De Bruijn index of 'a to D1 (the innermost binder).

If we invoke shift_out_to_binder and the region is in fact bound by one of the binders we are shifting out of, that is an error (and should fail an assertion failure).

pub fn keep_in_local_tcx(&self) -> bool[src]

⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

pub fn type_flags(&self) -> TypeFlags[src]

⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

pub fn free_region_binding_scope(&self, tcx: TyCtxt) -> DefId[src]

⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

Given an early-bound or free region, returns the DefId where it was bound. For example, consider the regions in this snippet of code:

impl<'a> Foo {
     ^^ -- early bound, declared on an impl

    fn bar<'b, 'c>(x: &self, y: &'b u32, z: &'c u64) where 'static: 'c
           ^^  ^^     ^ anonymous, late-bound
           |   early-bound, appears in where-clauses
           late-bound, appears only in fn args
    {..}
}

Here, free_region_binding_scope('a) would return the DefId of the impl, and for all the other highlighted regions, it would return the DefId of the function. In other cases (not shown), this function might return the DefId of a closure.

Trait Implementations

impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for RegionKind[src]

type Output = P::Region

⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

type Error = P::Error

⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

impl<'tcx> From<&'tcx RegionKind> for GenericArg<'tcx>[src]

impl Clone for RegionKind[src]

impl Copy for RegionKind[src]

impl Eq for RegionKind[src]

impl Ord for RegionKind[src]

impl PartialEq<RegionKind> for RegionKind[src]

impl PartialOrd<RegionKind> for RegionKind[src]

impl Debug for RegionKind[src]

impl Display for RegionKind[src]

impl Hash for RegionKind[src]

impl StructuralPartialEq for RegionKind[src]

impl StructuralEq for RegionKind[src]

impl<'tcx> Borrow<RegionKind> for Interned<'tcx, RegionKind>[src]

impl Encodable for RegionKind[src]

impl Decodable for RegionKind[src]

impl<'a> HashStable<StableHashingContext<'a>> for RegionKind[src]

impl<'a, 'tcx> SpecializedDecoder<&'tcx RegionKind> for CacheDecoder<'a, 'tcx>[src]

Auto Trait Implementations

impl Send for RegionKind

impl Sync for RegionKind

impl Unpin for RegionKind

impl UnwindSafe for RegionKind

impl RefUnwindSafe for RegionKind

Blanket Implementations

impl<T> ArenaAllocatable for T where
    T: Copy
[src]

impl<T> MaybeResult<T> for T[src]

type Error = !

⚙️ This is an internal compiler API. (rustc_private)

This crate is being loaded from the sysroot, a permanently unstable location for private compiler dependencies. It is not intended for general use. Prefer using a public version of this crate from crates.io via Cargo.toml.

impl<'a, T> Captures<'a> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Encodable for T where
    T: UseSpecializedEncodable + ?Sized
[src]

impl<T> Decodable for T where
    T: UseSpecializedDecodable
[src]

impl<T> Erased for T[src]

impl<E> SpecializationError for E[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]