Struct yoke::kinda_sorta_dangling::KindaSortaDangling

source ·
#[repr(transparent)]
pub(crate) struct KindaSortaDangling<T: 'static> { dangle: MaybeUninit<T>, }
Expand description

This type is intended to be similar to the type MaybeDangling<T> proposed in RFC 3336.

The effect of this is that in Rust’s safety model, types inside here are not expected to have any memory dependent validity properties (dereferenceable, noalias).

See #3696 for a testcase where Yoke fails under miri’s field-retagging mode if not using KindaSortaDangling.

This has T: 'static since we don’t need anything else and we don’t want to have to think (more) about variance over lifetimes or dropck.

After RFC 3336 lands we can use MaybeDangling instead.

Note that a version of this type also exists publicly as the [maybe_dangling] crate; which also exports a patched ManuallyDrop with similar semantics and does not require T: 'static. Consider using this if you need something more general and are okay with adding dependencies.

maybe_dangling

Fields§

§dangle: MaybeUninit<T>

Safety invariant: This is always an initialized T, never uninit or other invalid bit patterns. Its drop glue will execute during Drop::drop rather than during the drop glue for KindaSortaDangling, which means that we have to be careful about not touching the values as initialized during drop after that, but that’s a short period of time.

Implementations§

source§

impl<T: 'static> KindaSortaDangling<T>

source

pub(crate) const fn new(dangle: T) -> Self

source

pub(crate) fn into_inner(self) -> T

Trait Implementations§

source§

impl<T: 'static> Deref for KindaSortaDangling<T>

source§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<T: 'static> DerefMut for KindaSortaDangling<T>

source§

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

Mutably dereferences the value.
source§

impl<T: 'static> Drop for KindaSortaDangling<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for KindaSortaDangling<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for KindaSortaDangling<T>
where T: RefUnwindSafe,

§

impl<T> Send for KindaSortaDangling<T>
where T: Send,

§

impl<T> Sync for KindaSortaDangling<T>
where T: Sync,

§

impl<T> Unpin for KindaSortaDangling<T>
where T: Unpin,

§

impl<T> UnwindSafe for KindaSortaDangling<T>
where T: 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> 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, U> TryFrom<U> for T
where U: Into<T>,

source§

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>,

source§

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.
source§

impl<T> ErasedDestructor for T
where T: 'static,