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
A block whose only statement is a let drops that value at the end of the function, not the block (§2.4) #1851
§2.4 (drop points): a value is dropped at the end of the scope that owns it; a { ... } block is a scope.
Repro
type Tok:
n: i32
impl Drop for Tok:
move fn drop(): print(f"drop {self.n}")
fn main:
{
let t = Tok { n: 1 }
}
print("end")
with run --debug-alloc (installed main, and fix-globals stage1): prints end then drop 1. Expected drop 1 then end.
A block with a statement after the let drops on time ({ let u = Tok { n: 2 }; print("in") } prints in, drop 2 before the code after it), and so does an if body holding only a let.
t (_1) is scheduled at main's scope exit: the block's scope never closes, so its only binding lives to the end of the function. A Drop with an effect (a lock guard, a file, a global write) runs late.
Found while fixing #1847. Not yet located at the line (parser shape vs MirLower scope close).
Activity
Box[dyn Trait] drops what it holds, exactly once, then frees its cell…
Parser: a `{ }` block holding one binding or defer is still its scope…