pub enum FakeReadCause {
    ForMatchGuard,
    ForMatchedPlace(Option<LocalDefId>),
    ForGuardBinding,
    ForLet(Option<LocalDefId>),
    ForIndex,
}
Expand description

The FakeReadCause describes the type of pattern why a FakeRead statement exists.

Variants§

§

ForMatchGuard

Inject a fake read of the borrowed input at the end of each guards code.

This should ensure that you cannot change the variant for an enum while you are in the midst of matching on it.

§

ForMatchedPlace(Option<LocalDefId>)

let x: !; match x {} doesn’t generate any read of x so we need to generate a read of x to check that it is initialized and safe.

If a closure pattern matches a Place starting with an Upvar, then we introduce a FakeRead for that Place outside the closure, in such a case this option would be Some(closure_def_id). Otherwise, the value of the optional LocalDefId will be None.

§

ForGuardBinding

A fake read of the RefWithinGuard version of a bind-by-value variable in a match guard to ensure that its value hasn’t change by the time we create the OutsideGuard version.

§

ForLet(Option<LocalDefId>)

Officially, the semantics of

let pattern = <expr>;

is that <expr> is evaluated into a temporary and then this temporary is into the pattern.

However, if we see the simple pattern let var = <expr>, we optimize this to evaluate <expr> directly into the variable var. This is mostly unobservable, but in some cases it can affect the borrow checker, as in #53695. Therefore, we insert a “fake read” here to ensure that we get appropriate errors.

If a closure pattern matches a Place starting with an Upvar, then we introduce a FakeRead for that Place outside the closure, in such a case this option would be Some(closure_def_id). Otherwise, the value of the optional DefId will be None.

§

ForIndex

If we have an index expression like

(*x)[1][{ x = y; 4}]

then the first bounds check is invalidated when we evaluate the second index expression. Thus we create a fake borrow of x across the second indexer, which will cause a borrow check error.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> CallHasher for Twhere T: Hash + ?Sized,

§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64where H: Hash + ?Sized, B: BuildHasher,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.