Struct chalk_solve::infer::var::EnaVariable
source · pub struct EnaVariable<I: Interner> {
var: InferenceVar,
phantom: PhantomData<I>,
}
Expand description
Wrapper around chalk_ir::InferenceVar
for coherence purposes.
An inference variable represents an unknown term – either a type
or a lifetime. The variable itself is just an index into the
unification table; the unification table maps it to an
InferenceValue
.
Inference variables can be in one of two states (represents by the variants
of an InferenceValue
):
- Unbound(
ui
). In this case, the value of the variable is not yet known. We carry along a universe indexui
that tracks the universe in which the variable was created; this determines what names may appear in the variable’s value.- In this state, we do not track the kind of this variable (i.e., whether it represents a type or a lifetime). There is no need: if it represents a lifetime, for example, then there should only ever be constraints that relate it to other lifetimes, or use it in lifetime position.
- Bound. In this case, the value of the variable is known. We
carry along the value. We discard the universe index in which
the variable was created, since that was only needed to help us
reject illegal values. Once the value of a variable is known, it
can never change.
- The value we actually store for variables is a
ir::GenericArg
, and hence it does carry along the kind of the variable via the enum variant. However, we should always know the kind of the variable from context, and hence we typically “downcast” the resulting variable using e.g.value.ty().unwrap()
.
- The value we actually store for variables is a
Fields§
§var: InferenceVar
§phantom: PhantomData<I>
Implementations§
source§impl<I: Interner> EnaVariable<I>
impl<I: Interner> EnaVariable<I>
sourcepub fn to_ty_with_kind(self, interner: I, kind: TyVariableKind) -> Ty<I>
pub fn to_ty_with_kind(self, interner: I, kind: TyVariableKind) -> Ty<I>
Convert this inference variable into a type. When using this method, naturally you should know from context that the kind of this inference variable is a type (we can’t check it).
sourcepub fn to_ty(self, interner: I) -> Ty<I>
pub fn to_ty(self, interner: I) -> Ty<I>
Same as to_ty_with_kind
, but the kind is set to TyVariableKind::General
.
This should be used instead of to_ty_with_kind
when creating a new
inference variable (when the kind is not known).
sourcepub fn to_lifetime(self, interner: I) -> Lifetime<I>
pub fn to_lifetime(self, interner: I) -> Lifetime<I>
Convert this inference variable into a lifetime. When using this method, naturally you should know from context that the kind of this inference variable is a lifetime (we can’t check it).
Trait Implementations§
source§impl<I: Clone + Interner> Clone for EnaVariable<I>
impl<I: Clone + Interner> Clone for EnaVariable<I>
source§fn clone(&self) -> EnaVariable<I>
fn clone(&self) -> EnaVariable<I>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<I: Interner> Debug for EnaVariable<I>
impl<I: Interner> Debug for EnaVariable<I>
source§impl<I: Interner> From<EnaVariable<I>> for InferenceVar
impl<I: Interner> From<EnaVariable<I>> for InferenceVar
source§fn from(ena_var: EnaVariable<I>) -> InferenceVar
fn from(ena_var: EnaVariable<I>) -> InferenceVar
source§impl<I: Interner> From<InferenceVar> for EnaVariable<I>
impl<I: Interner> From<InferenceVar> for EnaVariable<I>
source§fn from(var: InferenceVar) -> EnaVariable<I>
fn from(var: InferenceVar) -> EnaVariable<I>
source§impl<I: Ord + Interner> Ord for EnaVariable<I>
impl<I: Ord + Interner> Ord for EnaVariable<I>
source§fn cmp(&self, other: &EnaVariable<I>) -> Ordering
fn cmp(&self, other: &EnaVariable<I>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<I: PartialEq + Interner> PartialEq for EnaVariable<I>
impl<I: PartialEq + Interner> PartialEq for EnaVariable<I>
source§fn eq(&self, other: &EnaVariable<I>) -> bool
fn eq(&self, other: &EnaVariable<I>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<I: PartialOrd + Interner> PartialOrd for EnaVariable<I>
impl<I: PartialOrd + Interner> PartialOrd for EnaVariable<I>
source§fn partial_cmp(&self, other: &EnaVariable<I>) -> Option<Ordering>
fn partial_cmp(&self, other: &EnaVariable<I>) -> 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<I: Interner> UnifyKey for EnaVariable<I>
impl<I: Interner> UnifyKey for EnaVariable<I>
type Value = InferenceValue<I>
fn index(&self) -> u32
fn from_index(u: u32) -> Self
fn tag() -> &'static str
§fn order_roots(
a: Self,
a_value: &Self::Value,
b: Self,
b_value: &Self::Value,
) -> Option<(Self, Self)>
fn order_roots( a: Self, a_value: &Self::Value, b: Self, b_value: &Self::Value, ) -> Option<(Self, Self)>
impl<I: Copy + Interner> Copy for EnaVariable<I>
impl<I: Eq + Interner> Eq for EnaVariable<I>
impl<I: Interner> StructuralPartialEq for EnaVariable<I>
Auto Trait Implementations§
impl<I> Freeze for EnaVariable<I>
impl<I> RefUnwindSafe for EnaVariable<I>where
I: RefUnwindSafe,
impl<I> Send for EnaVariable<I>where
I: Send,
impl<I> Sync for EnaVariable<I>where
I: Sync,
impl<I> Unpin for EnaVariable<I>where
I: Unpin,
impl<I> UnwindSafe for EnaVariable<I>where
I: UnwindSafe,
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> Cast for T
impl<T> Cast for T
source§fn cast<U>(self, interner: <U as HasInterner>::Interner) -> Uwhere
Self: CastTo<U>,
U: HasInterner,
fn cast<U>(self, interner: <U as HasInterner>::Interner) -> Uwhere
Self: CastTo<U>,
U: HasInterner,
U
using CastTo
.source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.