Struct rustc_type_ir::UniverseIndex
source · [−]pub struct UniverseIndex {
pub(crate) private: u32,
}
Expand description
“Universes” are used during type- and trait-checking in the
presence of for<..>
binders to control what sets of names are
visible. Universes are arranged into a tree: the root universe
contains names that are always visible. Each child then adds a new
set of names that are visible, in addition to those of its parent.
We say that the child universe “extends” the parent universe with
new names.
To make this more concrete, consider this program:
struct Foo { }
fn bar<T>(x: T) {
let y: for<'a> fn(&'a u8, Foo) = ...;
}
The struct name Foo
is in the root universe U0. But the type
parameter T
, introduced on bar
, is in an extended universe U1
– i.e., within bar
, we can name both T
and Foo
, but outside
of bar
, we cannot name T
. Then, within the type of y
, the
region 'a
is in a universe U2 that extends U1, because we can
name it inside the fn type but not outside.
Universes are used to do type- and trait-checking around these
“forall” binders (also called universal quantification). The
idea is that when, in the body of bar
, we refer to T
as a
type, we aren’t referring to any type in particular, but rather a
kind of “fresh” type that is distinct from all other types we have
actually declared. This is called a placeholder type, and we
use universes to talk about this. In other words, a type name in
universe 0 always corresponds to some “ground” type that the user
declared, but a type name in a non-zero universe is a placeholder
type – an idealized representative of “types in general” that we
use for checking generic functions.
Fields
private: u32
Implementations
sourceimpl UniverseIndex
impl UniverseIndex
sourcepub const MAX_AS_U32: u32 = 4_294_967_040u32
pub const MAX_AS_U32: u32 = 4_294_967_040u32
Maximum value the index can take, as a u32
.
sourcepub const fn from_usize(value: usize) -> Self
pub const fn from_usize(value: usize) -> Self
sourcepub const unsafe fn from_u32_unchecked(value: u32) -> Self
pub const unsafe fn from_u32_unchecked(value: u32) -> Self
Creates a new index from a given u32
.
Safety
The provided value must be less than or equal to the maximum value for the newtype. Providing a value outside this range is undefined due to layout restrictions.
Prefer using from_u32
.
sourceimpl UniverseIndex
impl UniverseIndex
pub const ROOT: UniverseIndex = _
sourcepub fn next_universe(self) -> UniverseIndex
pub fn next_universe(self) -> UniverseIndex
Returns the “next” universe index in order – this new index
is considered to extend all previous universes. This
corresponds to entering a forall
quantifier. So, for
example, suppose we have this type in universe U
:
for<'a> fn(&'a u32)
Once we “enter” into this for<'a>
quantifier, we are in a
new universe that extends U
– in this new universe, we can
name the region 'a
, but that region was not nameable from
U
because it was not in scope there.
sourcepub fn can_name(self, other: UniverseIndex) -> bool
pub fn can_name(self, other: UniverseIndex) -> bool
Returns true
if self
can name a name from other
– in other words,
if the set of names in self
is a superset of those in
other
(self >= other
).
sourcepub fn cannot_name(self, other: UniverseIndex) -> bool
pub fn cannot_name(self, other: UniverseIndex) -> bool
Returns true
if self
cannot name some names from other
– in other
words, if the set of names in self
is a strict subset of
those in other
(self < other
).
Trait Implementations
sourceimpl Add<usize> for UniverseIndex
impl Add<usize> for UniverseIndex
sourceimpl Clone for UniverseIndex
impl Clone for UniverseIndex
sourcefn clone(&self) -> UniverseIndex
fn clone(&self) -> UniverseIndex
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl Debug for UniverseIndex
impl Debug for UniverseIndex
sourceimpl From<UniverseIndex> for u32
impl From<UniverseIndex> for u32
sourcefn from(v: UniverseIndex) -> u32
fn from(v: UniverseIndex) -> u32
sourceimpl From<UniverseIndex> for usize
impl From<UniverseIndex> for usize
sourcefn from(v: UniverseIndex) -> usize
fn from(v: UniverseIndex) -> usize
sourceimpl From<u32> for UniverseIndex
impl From<u32> for UniverseIndex
sourceimpl From<usize> for UniverseIndex
impl From<usize> for UniverseIndex
sourceimpl Hash for UniverseIndex
impl Hash for UniverseIndex
sourceimpl<__CTX> HashStable<__CTX> for UniverseIndexwhere
__CTX: HashStableContext,
impl<__CTX> HashStable<__CTX> for UniverseIndexwhere
__CTX: HashStableContext,
fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)
sourceimpl Idx for UniverseIndex
impl Idx for UniverseIndex
sourceimpl Ord for UniverseIndex
impl Ord for UniverseIndex
sourcefn cmp(&self, other: &UniverseIndex) -> Ordering
fn cmp(&self, other: &UniverseIndex) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl PartialEq<UniverseIndex> for UniverseIndex
impl PartialEq<UniverseIndex> for UniverseIndex
sourcefn eq(&self, other: &UniverseIndex) -> bool
fn eq(&self, other: &UniverseIndex) -> bool
sourceimpl PartialOrd<UniverseIndex> for UniverseIndex
impl PartialOrd<UniverseIndex> for UniverseIndex
sourcefn partial_cmp(&self, other: &UniverseIndex) -> Option<Ordering>
fn partial_cmp(&self, other: &UniverseIndex) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceimpl Step for UniverseIndex
impl Step for UniverseIndex
sourcefn steps_between(start: &Self, end: &Self) -> Option<usize>
fn steps_between(start: &Self, end: &Self) -> Option<usize>
step_trait
)sourcefn forward_checked(start: Self, u: usize) -> Option<Self>
fn forward_checked(start: Self, u: usize) -> Option<Self>
step_trait
)sourcefn backward_checked(start: Self, u: usize) -> Option<Self>
fn backward_checked(start: Self, u: usize) -> Option<Self>
step_trait
)sourcefn forward(start: Self, count: usize) -> Self
fn forward(start: Self, count: usize) -> Self
step_trait
)sourceunsafe fn forward_unchecked(start: Self, count: usize) -> Self
unsafe fn forward_unchecked(start: Self, count: usize) -> Self
step_trait
)sourcefn backward(start: Self, count: usize) -> Self
fn backward(start: Self, count: usize) -> Self
step_trait
)sourceunsafe fn backward_unchecked(start: Self, count: usize) -> Self
unsafe fn backward_unchecked(start: Self, count: usize) -> Self
step_trait
)impl Copy for UniverseIndex
impl Eq for UniverseIndex
impl StructuralEq for UniverseIndex
impl StructuralPartialEq for UniverseIndex
impl TrustedStep for UniverseIndex
Auto Trait Implementations
impl RefUnwindSafe for UniverseIndex
impl Send for UniverseIndex
impl Sync for UniverseIndex
impl Unpin for UniverseIndex
impl UnwindSafe for UniverseIndex
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T, R> InternIteratorElement<T, R> for T
impl<T, R> InternIteratorElement<T, R> for T
type Output = R
fn intern_with<I, F>(iter: I, f: F) -> <T as InternIteratorElement<T, R>>::Outputwhere
I: Iterator<Item = T>,
F: FnOnce(&[T]) -> R,
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: 4 bytes