On 5/25/12 10:28 AM, Patrick Walton wrote:
I've been toying with the idea of changing standard Rust RAII to
"execute this when the variable goes dead" (in the classic compiler
liveness sense) and introduce a "scope" keyword for something more
like C++ or D RAII in which the liveness of the variable is restricted
to be exactly the extent of the block, making it safe to
unconditionally run the destructor once the variable goes out of scope.
It seems like the official rule could be as simple as "the destructor is
executed at some point after the last access and before the exit from
the scope". This would give us more freedom.
I don't know the details of the D version, but I like the idea of scope
as it makes it more explicit when you are creating a resource just for
side-effects. It also avoids the need for unused variables. For
example, this code that is sprinkled throughout trans:
let _icx = cx.insn_ctxt("trans_local_var");
would become something like:
scope cx.insn_ctxt("trans_local_var");
which seems much clearer to me.
Niko
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev