Enum rustc_middle::ty::RegionKind [−][src]
pub enum RegionKind {
ReEarlyBound(EarlyBoundRegion),
ReLateBound(DebruijnIndex, BoundRegion),
ReFree(FreeRegion),
ReStatic,
ReVar(RegionVid),
RePlaceholder(PlaceholderRegion),
ReEmpty(UniverseIndex),
ReErased,
}Expand description
Representation of regions. Note that the NLL checker uses a distinct
representation of regions. For this reason, it internally replaces all the
regions with inference variables – the index of the variable is then used
to index into internal NLL data structures. See rustc_mir::borrow_check
module for more information.
The Region lattice within a given function
In general, the region lattice looks like
static ----------+-----...------+ (greatest) | | | early-bound and | | free regions | | | | | | | | empty(root) placeholder(U1) | | / | | / placeholder(Un) empty(U1) -- / | / ... / | / empty(Un) -------- (smallest)
Early-bound/free regions are the named lifetimes in scope from the function declaration. They have relationships to one another determined based on the declared relationships from the function.
Note that inference variables and bound regions are not included in this diagram. In the case of inference variables, they should be inferred to some other region from the diagram. In the case of bound regions, they are excluded because they don’t make sense to include – the diagram indicates the relationship between free regions.
Inference variables
During region inference, we sometimes create inference variables,
represented as ReVar. These will be inferred by the code in
infer::lexical_region_resolve to some free region from the
lattice above (the minimal region that meets the
constraints).
During NLL checking, where regions are defined differently, we
also use ReVar – in that case, the index is used to index into
the NLL region checker’s data structures. The variable may in fact
represent either a free region or an inference variable, in that
case.
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 dev guide.
Variants
ReEarlyBound(EarlyBoundRegion)Expand description
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(DebruijnIndex, BoundRegion)Expand description
Region bound in a function scope, which will be substituted when the function is called.
ReFree(FreeRegion)Expand description
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.
Expand description
Static data that has an “infinite” lifetime. Top in the region lattice.
ReVar(RegionVid)Expand description
A region variable. Should not exist after typeck.
RePlaceholder(PlaceholderRegion)Expand description
A placeholder region – basically, the higher-ranked version of ReFree.
Should not exist after typeck.
ReEmpty(UniverseIndex)Expand description
Empty lifetime is for data that is never accessed. We tag the
empty lifetime with a universe – the idea is that we don’t
want exists<'a> { forall<'b> { 'b: 'a } } to be satisfiable.
Therefore, the 'empty in a universe U is less than all
regions visible from U, but not less than regions not visible
from U.
Expand description
Erased region, used by trait selection, in MIR and during codegen.
Implementations
impl RegionKind[src]
impl RegionKind[src]Region utilities
pub fn is_late_bound(&self) -> bool[src]
pub fn is_placeholder(&self) -> bool[src]
pub fn bound_at_or_above_binder(&self, index: DebruijnIndex) -> bool[src]
pub fn type_flags(&self) -> TypeFlags[src]
pub fn free_region_binding_scope(&self, tcx: TyCtxt<'_>) -> DefId[src]
pub fn free_region_binding_scope(&self, tcx: TyCtxt<'_>) -> DefId[src]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> Borrow<RegionKind> for Interned<'tcx, RegionKind>[src]
impl<'tcx> Borrow<RegionKind> for Interned<'tcx, RegionKind>[src]fn borrow(&self) -> &RegionKind[src]
fn borrow(&self) -> &RegionKind[src]Immutably borrows from an owned value. Read more
impl Clone for RegionKind[src]
impl Clone for RegionKind[src]fn clone(&self) -> RegionKind[src]
fn clone(&self) -> RegionKind[src]Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]Performs copy-assignment from source. Read more
impl Debug for RegionKind[src]
impl Debug for RegionKind[src]impl<'tcx, __D: TyDecoder<'tcx>> Decodable<__D> for RegionKind[src]
impl<'tcx, __D: TyDecoder<'tcx>> Decodable<__D> for RegionKind[src]impl Display for RegionKind[src]
impl Display for RegionKind[src]impl<'tcx, __E: TyEncoder<'tcx>> Encodable<__E> for RegionKind[src]
impl<'tcx, __E: TyEncoder<'tcx>> Encodable<__E> for RegionKind[src]impl<'tcx> From<&'tcx RegionKind> for GenericArg<'tcx>[src]
impl<'tcx> From<&'tcx RegionKind> for GenericArg<'tcx>[src]fn from(r: Region<'tcx>) -> GenericArg<'tcx>[src]
fn from(r: Region<'tcx>) -> GenericArg<'tcx>[src]Performs the conversion.
impl Hash for RegionKind[src]
impl Hash for RegionKind[src]impl<'a> HashStable<StableHashingContext<'a>> for RegionKind[src]
impl<'a> HashStable<StableHashingContext<'a>> for RegionKind[src]fn hash_stable(
&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher
)[src]
&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher
)
impl Ord for RegionKind[src]
impl Ord for RegionKind[src]impl PartialEq<RegionKind> for RegionKind[src]
impl PartialEq<RegionKind> for RegionKind[src]fn eq(&self, other: &RegionKind) -> bool[src]
fn eq(&self, other: &RegionKind) -> bool[src]This method tests for self and other values to be equal, and is used
by ==. Read more
fn ne(&self, other: &RegionKind) -> bool[src]
fn ne(&self, other: &RegionKind) -> bool[src]This method tests for !=.
impl PartialOrd<RegionKind> for RegionKind[src]
impl PartialOrd<RegionKind> for RegionKind[src]fn partial_cmp(&self, other: &RegionKind) -> Option<Ordering>[src]
fn partial_cmp(&self, other: &RegionKind) -> Option<Ordering>[src]This method returns an ordering between self and other values if one exists. Read more
#[must_use]fn lt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool1.0.0[src]This method tests less than (for self and other) and is used by the < operator. Read more
#[must_use]fn le(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool1.0.0[src]This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for RegionKind[src]
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for RegionKind[src]impl Copy for RegionKind[src]
impl Eq for RegionKind[src]
impl StructuralEq for RegionKind[src]
impl StructuralPartialEq for RegionKind[src]
Auto Trait Implementations
impl RefUnwindSafe for RegionKind
impl Send for RegionKind
impl Sync for RegionKind
impl Unpin for RegionKind
impl UnwindSafe for RegionKind
Blanket Implementations
impl<'tcx, T> ArenaAllocatable<'tcx, ()> for T where
T: Copy, [src]
impl<'tcx, T> ArenaAllocatable<'tcx, ()> for T where
T: Copy, [src]pub fn allocate_on(Self, &'a Arena<'tcx>) -> &'a mut T[src]
pub fn allocate_from_iter(
&'a Arena<'tcx>,
impl IntoIterator<Item = T>
) -> &'a mut [T]ⓘ[src]
&'a Arena<'tcx>,
impl IntoIterator<Item = T>
) -> &'a mut [T]ⓘ
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]pub fn borrow_mut(&mut self) -> &mut T[src]
pub fn borrow_mut(&mut self) -> &mut T[src]Mutably borrows from an owned value. Read more
impl<T> MaybeResult<T> for T[src]
impl<T> MaybeResult<T> for T[src]impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, [src]type Owned = T
type Owned = TThe resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn to_owned(&self) -> T[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)[src]
pub fn clone_into(&self, target: &mut T)[src]🔬 This is a nightly-only experimental API. (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> WithConstness for T[src]
impl<T> WithConstness for T[src]fn with_constness(self, constness: Constness) -> ConstnessAnd<Self>[src]
fn with_const(self) -> ConstnessAnd<Self>[src]
fn without_const(self) -> ConstnessAnd<Self>[src]
impl<'a, T> Captures<'a> for T where
T: ?Sized, [src]
T: ?Sized,