pub struct Adjustment {
pub kind: Adjust,
pub target: StoredTy,
}Expand description
Represents coercing a value to a different type of value.
We transform values by following a number of Adjust steps in order.
See the documentation on variants of Adjust for more details.
Here are some common scenarios:
-
The simplest cases are where a pointer is not adjusted fat vs thin. Here the pointer will be dereferenced N times (where a dereference can happen to raw or borrowed pointers or any smart pointer which implements Deref, including Box<_>). The types of dereferences is given by
autoderefs. It can then be auto-referenced zero or one times, indicated byautoref, to either a raw or borrowed pointer. In these cases unsize isfalse. -
A thin-to-fat coercion involves unsizing the underlying data. We start with a thin pointer, deref a number of times, unsize the underlying data, then autoref. The ‘unsize’ phase may change a fixed length array to a dynamically sized one, a concrete object to a trait object, or statically sized struct to a dynamically sized one. E.g., &[i32; 4] -> &i32 is represented by:
ⓘDeref(None) -> [i32; 4], Borrow(AutoBorrow::Ref) -> &[i32; 4], Unsize -> &[i32],Note that for a struct, the ‘deep’ unsizing of the struct is not recorded. E.g.,
struct Foo<T> { it: T }we can coerce &Foo<[i32; 4]> to &Foo<i32> The autoderef and -ref are the same as in the above example, but the type stored inunsizeisFoo<[i32]>, we don’t store any further detail about the underlying conversions from[i32; 4]to[i32]. -
Coercing a
Box<T>toBox<dyn Trait>is an interesting special case. In that case, we have the pointer we need coming in, so there are no autoderefs, and no autoref. Instead we just do theUnsizetransformation. At some point, of course,Boxshould move out of the compiler, in which case this is analogous to transforming a struct. E.g., Box<[i32; 4]> -> Box<i32> is anAdjust::Unsizewith the targetBox<[i32]>.
Fields§
§kind: Adjust§target: StoredTyImplementations§
Source§impl Adjustment
impl Adjustment
pub fn borrow<'db>( interner: DbInterner<'db>, m: Mutability, ty: Ty<'db>, lt: Region<'db>, ) -> Self
Trait Implementations§
Source§impl Clone for Adjustment
impl Clone for Adjustment
Source§fn clone(&self) -> Adjustment
fn clone(&self) -> Adjustment
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Adjustment
impl Debug for Adjustment
Source§impl Hash for Adjustment
impl Hash for Adjustment
Source§impl PartialEq for Adjustment
impl PartialEq for Adjustment
Source§fn eq(&self, other: &Adjustment) -> bool
fn eq(&self, other: &Adjustment) -> bool
self and other values to be equal, and is used by ==.impl Eq for Adjustment
impl StructuralPartialEq for Adjustment
Auto Trait Implementations§
impl Freeze for Adjustment
impl RefUnwindSafe for Adjustment
impl Send for Adjustment
impl Sync for Adjustment
impl Unpin for Adjustment
impl UnsafeUnpin for Adjustment
impl UnwindSafe for Adjustment
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
§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.§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
§impl<T> HashEqLike<T> for T
impl<T> HashEqLike<T> for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more