Enum flowistry_pdg::rustc::mir::FakeReadCause
source · 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.