Struct hir_ty::Adjustment
source · pub struct Adjustment {
pub kind: Adjust,
pub target: Ty,
}
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 inunsize
isFoo<[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 theUnsize
transformation. At some point, of course,Box
should move out of the compiler, in which case this is analogous to transforming a struct. E.g., Box<[i32; 4]> -> Box<i32> is anAdjust::Unsize
with the targetBox<[i32]>
.
Fields§
§kind: Adjust
§target: Ty
Implementations§
source§impl Adjustment
impl Adjustment
pub fn borrow(m: Mutability, ty: Ty, lt: Lifetime) -> Self
Trait Implementations§
source§impl Clone for Adjustment
impl Clone for Adjustment
source§fn clone(&self) -> Adjustment
fn clone(&self) -> Adjustment
1.0.0 · 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
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 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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§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.§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