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 index ui 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().

Fields§

§var: InferenceVar§phantom: PhantomData<I>

Implementations§

source§

impl<I: Interner> EnaVariable<I>

source

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).

source

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).

source

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).

source

pub fn to_const(self, interner: I, ty: Ty<I>) -> Const<I>

Convert this inference variable into a const. When using this method, naturally you should know from context that the kind of this inference variable is a const (we can’t check it).

Trait Implementations§

source§

impl<I: Clone + Interner> Clone for EnaVariable<I>

source§

fn clone(&self) -> EnaVariable<I>

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<I: Interner> Debug for EnaVariable<I>

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<I: Interner> From<EnaVariable<I>> for InferenceVar

source§

fn from(ena_var: EnaVariable<I>) -> InferenceVar

Converts to this type from the input type.
source§

impl<I: Interner> From<InferenceVar> for EnaVariable<I>

source§

fn from(var: InferenceVar) -> EnaVariable<I>

Converts to this type from the input type.
source§

impl<I: Hash + Interner> Hash for EnaVariable<I>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<I: Ord + Interner> Ord for EnaVariable<I>

source§

fn cmp(&self, other: &EnaVariable<I>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<I: PartialEq + Interner> PartialEq for EnaVariable<I>

source§

fn eq(&self, other: &EnaVariable<I>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<I: PartialOrd + Interner> PartialOrd for EnaVariable<I>

source§

fn partial_cmp(&self, other: &EnaVariable<I>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<I: Interner> UnifyKey for EnaVariable<I>

§

type Value = InferenceValue<I>

source§

fn index(&self) -> u32

source§

fn from_index(u: u32) -> Self

source§

fn tag() -> &'static str

§

fn order_roots( a: Self, a_value: &Self::Value, b: Self, b_value: &Self::Value, ) -> Option<(Self, Self)>

You should return first the key that should be used as root, then the other key (that will then point to the new root). Read more
source§

impl<I: Copy + Interner> Copy for EnaVariable<I>

source§

impl<I: Eq + Interner> Eq for EnaVariable<I>

source§

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> 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> Cast for T

source§

fn cast<U>(self, interner: <U as HasInterner>::Interner) -> U
where Self: CastTo<U>, U: HasInterner,

Cast a value to type U using CastTo.
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

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

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<N> NodeTrait for N
where N: Copy + Ord + Hash,