You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sema: a move inside a let-else's diverging else body marks the value moved after the let-else #1383
The else body of a let-else diverges (§9.7), so a value it consumes is still live on the continuing path. Sema's check_let_else (src/SemaCheck.w ~15295) checks the else body in the enclosing move state and never restores it, so a later use is rejected as use-after-move.
fn vec_or_err(k: i32) -> Result[Vec[str], str]:
if k == 0: return Err("none".clone())
var v: Vec[str] = Vec.new()
v.push("a".clone())
v
fn consume(s: str) -> i32: s.len() as i32
fn h(k: i32) -> i32:
let keep = "keep".clone()
let Ok(v) = vec_or_err(k) else: return consume(keep) - 100
keep.len() as i32 + v.len() as i32
fn main:
print(f"{h(0)} {h(1)}")
Actual (v0.15.2.1 and origin/main 8c859a7): error: ... a moved value cannot be used again at keep.len().
Expected: -96 5. The equivalent if spelling (if ...: return consume(keep) - 100) is accepted.
MIR lowering is path-correct after #1365 (the else body is lowered under a saved move state that is restored for the continuation), so once Sema accepts this the program must run clean under --debug-alloc; add it to the #1365 fixture test/debug_alloc/da_let_else_fail_owned_payload.w when this lands.
Found while building the #1365 let-else drop matrix.
Activity
let-else: the failing path drops the whole subject before it diverges…
let-else: the failing path drops the whole subject before it diverges…
let-else: a move in the diverging else branch stays on that path — Se…
let-else: a move in the diverging else branch stays on that path — Se…
validate-ownership: a reset-on-move blank of a place no path moved (s…
Ownership: D72 liveness byte, D73 assignment-as-read, validator leak/…