Skip to main content

IsFreeVarSafe

Function IsFreeVarSafe 

Source
pub fn IsFreeVarSafe(Init: &Expr, StmtsBetween: &[Stmt]) -> bool
Expand description

Returns true when every plain-identifier free variable inside Init remains live (not moved by value) in the statements that appear between the candidate let-binding (exclusive) and the substitution site (exclusive).

Stmts is the slice Block.stmts[CandidateIndex + 1..SubstSite] - i.e. the statements that execute after the let but before the single use.

The check is conservative: it only tracks Expr::Path single-segment bare identifiers. Qualified paths (a::b), method receivers (.foo()), and reference borrows (&x) are all ignored, so false positives (keeping a binding that would have been safe) are possible but false negatives that would introduce a compile error are not.