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§
source§impl 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
.
source§impl 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§
source§impl Add<usize> for UniverseIndex
impl Add<usize> for UniverseIndex
source§impl Clone for UniverseIndex
impl Clone for UniverseIndex
source§fn clone(&self) -> UniverseIndex
fn clone(&self) -> UniverseIndex
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for UniverseIndex
impl Debug for UniverseIndex
source§impl From<UniverseIndex> for u32
impl From<UniverseIndex> for u32
source§fn from(v: UniverseIndex) -> u32
fn from(v: UniverseIndex) -> u32
source§impl From<UniverseIndex> for usize
impl From<UniverseIndex> for usize
source§fn from(v: UniverseIndex) -> usize
fn from(v: UniverseIndex) -> usize
source§impl From<u32> for UniverseIndex
impl From<u32> for UniverseIndex
source§impl From<usize> for UniverseIndex
impl From<usize> for UniverseIndex
source§impl Hash for UniverseIndex
impl Hash for UniverseIndex
source§impl<__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)
source§impl Idx for UniverseIndex
impl Idx for UniverseIndex
source§impl Ord for UniverseIndex
impl Ord for UniverseIndex
source§fn cmp(&self, other: &UniverseIndex) -> Ordering
fn cmp(&self, other: &UniverseIndex) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<UniverseIndex> for UniverseIndex
impl PartialEq<UniverseIndex> for UniverseIndex
source§fn eq(&self, other: &UniverseIndex) -> bool
fn eq(&self, other: &UniverseIndex) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<UniverseIndex> for UniverseIndex
impl PartialOrd<UniverseIndex> for UniverseIndex
source§fn partial_cmp(&self, other: &UniverseIndex) -> Option<Ordering>
fn partial_cmp(&self, other: &UniverseIndex) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Step for UniverseIndex
impl Step for UniverseIndex
source§fn steps_between(start: &Self, end: &Self) -> Option<usize>
fn steps_between(start: &Self, end: &Self) -> Option<usize>
step_trait
)source§fn forward_checked(start: Self, u: usize) -> Option<Self>
fn forward_checked(start: Self, u: usize) -> Option<Self>
step_trait
)source§fn backward_checked(start: Self, u: usize) -> Option<Self>
fn backward_checked(start: Self, u: usize) -> Option<Self>
step_trait
)source§fn forward(start: Self, count: usize) -> Self
fn forward(start: Self, count: usize) -> Self
step_trait
)source§unsafe fn forward_unchecked(start: Self, count: usize) -> Self
unsafe fn forward_unchecked(start: Self, count: usize) -> Self
step_trait
)source§fn backward(start: Self, count: usize) -> Self
fn backward(start: Self, count: usize) -> Self
step_trait
)source§unsafe 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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
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