pub struct TypeVariableStorage<'tcx> {
    values: IndexVec<TyVid, TypeVariableData>,
    eq_relations: UnificationTableStorage<TyVidEqKey<'tcx>>,
    sub_relations: UnificationTableStorage<TyVid>,
}

Fields§

§values: IndexVec<TyVid, TypeVariableData>

The origins of each type variable.

§eq_relations: UnificationTableStorage<TyVidEqKey<'tcx>>

Two variables are unified in eq_relations when we have a constraint ?X == ?Y. This table also stores, for each key, the known value.

§sub_relations: UnificationTableStorage<TyVid>

Two variables are unified in sub_relations when we have a constraint ?X <: ?Y or a constraint ?Y <: ?X. This second table exists only to help with the occurs check. In particular, we want to report constraints like these as an occurs check violation:

?1 <: ?3
Box<?3> <: ?1

Without this second table, what would happen in a case like this is that we would instantiate ?1 with a generalized type like Box<?6>. We would then relate Box<?3> <: Box<?6> and infer that ?3 <: ?6. Next, since ?1 was instantiated, we would process ?1 <: ?3, generalize ?1 = Box<?6> to Box<?9>, and instantiate ?3 with Box<?9>. Finally, we would relate ?6 <: ?9. But now that we instantiated ?3, we can process ?3 <: ?6, which gives us Box<?9> <: ?6… and the cycle continues. (This is occurs-check-2.rs.)

What prevents this cycle is that when we generalize Box<?3> to Box<?6>, we also sub-unify ?3 and ?6 (in the generalizer). When we then process Box<?6> <: ?3, the occurs check then fails because ?6 and ?3 are sub-unified, and hence generalization fails.

This is reasonable because, in Rust, subtypes have the same “skeleton” and hence there is no possible type such that (e.g.) Box<?3> <: ?3 for any ?3.

In practice, we sometimes sub-unify variables in other spots, such as when processing subtype predicates. This is not necessary but is done to aid diagnostics, as it allows us to be more effective when we guide the user towards where they should insert type hints.

Implementations§

source§

impl<'tcx> TypeVariableStorage<'tcx>

source

pub fn new() -> TypeVariableStorage<'tcx>

source

pub(crate) fn with_log<'a>( &'a mut self, undo_log: &'a mut InferCtxtUndoLogs<'tcx> ) -> TypeVariableTable<'a, 'tcx>

source

pub(crate) fn eq_relations_ref( &self ) -> &UnificationTableStorage<TyVidEqKey<'tcx>>

source

pub(super) fn finalize_rollback(&mut self)

Trait Implementations§

source§

impl<'tcx> Clone for TypeVariableStorage<'tcx>

source§

fn clone(&self) -> TypeVariableStorage<'tcx>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'tcx> Rollback<UndoLog<'tcx>> for TypeVariableStorage<'tcx>

source§

fn reverse(&mut self, undo: UndoLog<'tcx>)

Auto Trait Implementations§

§

impl<'tcx> !RefUnwindSafe for TypeVariableStorage<'tcx>

§

impl<'tcx> Send for TypeVariableStorage<'tcx>

§

impl<'tcx> Sync for TypeVariableStorage<'tcx>

§

impl<'tcx> Unpin for TypeVariableStorage<'tcx>

§

impl<'tcx> !UnwindSafe for TypeVariableStorage<'tcx>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

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: 72 bytes