Skip to main content

Coerce

Struct Coerce 

Source
struct Coerce<D> {
    delegate: D,
    use_lub: bool,
    allow_two_phase: AllowTwoPhase,
    coerce_never: bool,
    cause: ObligationCause,
}

Fields§

§delegate: D§use_lub: bool§allow_two_phase: AllowTwoPhase

Determines whether or not allow_two_phase_borrow is set on any autoref adjustments we create while coercing. We don’t want to allow deref coercions to create two-phase borrows, at least initially, but we do need two-phase borrows for function argument reborrows. See rust#47489 and rust#48598 See docs on the “AllowTwoPhase” type for a more detailed discussion

§coerce_never: bool

Whether we allow NeverToAny coercions. This is unsound if we’re coercing a place expression without it counting as a read in the MIR. This is a side-effect of HIR not really having a great distinction between places and values.

§cause: ObligationCause

Implementations§

Source§

impl<'db, D> Coerce<D>
where D: CoerceDelegate<'db>,

Source

fn infcx(&self) -> &InferCtxt<'db>

Source

fn param_env(&self) -> ParamEnv<'db>

Source

fn interner(&self) -> DbInterner<'db>

Source

fn db(&self) -> &'db dyn HirDatabase

Source

pub(crate) fn commit_if_ok<T, E>( &mut self, f: impl FnOnce(&mut Self) -> Result<T, E>, ) -> Result<T, E>

Source

fn unify_raw(&self, a: Ty<'db>, b: Ty<'db>) -> InferResult<'db, Ty<'db>>

Source

fn unify( &mut self, a: Ty<'db>, b: Ty<'db>, ) -> InferResult<'db, (Vec<Adjustment>, Ty<'db>)>

Unify two types (using sub or lub).

Source

fn unify_and( &mut self, a: Ty<'db>, b: Ty<'db>, adjustments: impl IntoIterator<Item = Adjustment>, final_adjustment: Adjust, ) -> InferResult<'db, (Vec<Adjustment>, Ty<'db>)>

Unify two types (using sub or lub) and produce a specific coercion.

Source

fn coerce( &mut self, a: Ty<'db>, b: Ty<'db>, ) -> InferResult<'db, (Vec<Adjustment>, Ty<'db>)>

Source

fn coerce_from_inference_variable( &mut self, a: Ty<'db>, b: Ty<'db>, ) -> InferResult<'db, (Vec<Adjustment>, Ty<'db>)>

Coercing from an inference variable. In this case, we have no information about the source type, so we can’t really do a true coercion and we always fall back to subtyping (unify_and).

Source

fn coerce_borrowed_pointer( &mut self, a: Ty<'db>, b: Ty<'db>, r_b: Region<'db>, mutbl_b: Mutability, ) -> InferResult<'db, (Vec<Adjustment>, Ty<'db>)>

Reborrows &mut A to &mut B and &(mut) A to &B. To match A with B, autoderef will be performed, calling deref/deref_mut where necessary.

Source

fn coerce_unsized( &mut self, source: Ty<'db>, target: Ty<'db>, ) -> InferResult<'db, (Vec<Adjustment>, Ty<'db>)>

Performs [unsized coercion] by emulating a fulfillment loop on a CoerceUnsized goal until all CoerceUnsized and Unsize goals are successfully selected.

unsized coercion

Source

fn coerce_from_safe_fn( &mut self, fn_ty_a: PolyFnSig<'db>, b: Ty<'db>, adjustment: Option<Adjust>, ) -> InferResult<'db, (Vec<Adjustment>, Ty<'db>)>

Source

fn coerce_from_fn_pointer( &mut self, fn_ty_a: PolyFnSig<'db>, b: Ty<'db>, ) -> InferResult<'db, (Vec<Adjustment>, Ty<'db>)>

Source

fn coerce_from_fn_item( &mut self, a: Ty<'db>, b: Ty<'db>, ) -> InferResult<'db, (Vec<Adjustment>, Ty<'db>)>

Source

fn coerce_closure_to_fn( &mut self, a: Ty<'db>, closure_def_id_a: InternedClosureId<'db>, args_a: GenericArgs<'db>, b: Ty<'db>, ) -> InferResult<'db, (Vec<Adjustment>, Ty<'db>)>

Attempts to coerce from the type of a non-capturing closure into a function pointer.

Source

fn coerce_raw_ptr( &mut self, a: Ty<'db>, b: Ty<'db>, mutbl_b: Mutability, ) -> InferResult<'db, (Vec<Adjustment>, Ty<'db>)>

Auto Trait Implementations§

§

impl<D> Freeze for Coerce<D>
where D: Freeze,

§

impl<D> RefUnwindSafe for Coerce<D>
where D: RefUnwindSafe,

§

impl<D> Send for Coerce<D>
where D: Send,

§

impl<D> Sync for Coerce<D>
where D: Sync,

§

impl<D> Unpin for Coerce<D>
where D: Unpin,

§

impl<D> UnsafeUnpin for Coerce<D>
where D: UnsafeUnpin,

§

impl<D> UnwindSafe for Coerce<D>
where D: 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
§

impl<T, R> CollectAndApply<T, R> for T

§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

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.

§

impl<T> IntoBox<dyn Any> for T
where T: Any,

§

fn into_box(self) -> Box<dyn Any>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn Any + Send> for T
where T: Any + Send,

§

fn into_box(self) -> Box<dyn Any + Send>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn Any + Send + Sync> for T
where T: Any + Send + Sync,

§

fn into_box(self) -> Box<dyn Any + Send + Sync>

Convert self into the appropriate boxed form.
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Lookup<T> for T

§

fn into_owned(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
§

impl<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

§

fn upcast(self, interner: I) -> U

§

impl<I, T> UpcastFrom<I, T> for T

§

fn upcast_from(from: T, _tcx: I) -> T

§

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