mozilla/rust — pull request #9842 by sfackler (2013-10-14 00:40:40+00:00)
Title: Add scope guards to libstd

This adds a struct which runs a block when it falls out of scope,
similar to `scope` in D or `defer` in Go. Using this module directly
requires code to assign the ScopeGuard struct to a variable manually
which is unnecessary in many situations.

It'd be nice to add a syntax extension to automatically expand
```rust
scope!(success) {
...
}
```
to something like
```rust
let __scope____ = ::std::scope::guard(::std::scope::Success, { ... });
```
but I don't think that syntax extensions can currently expand to statements as opposed to expressions or items and I'm not familiar enough with libsyntax to add it easily. I put this in libstd instead of libextra since it'll need to be there for the syntax extension to work reasonably.

cc #9835