-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement scope guards, as a syntax ext or language feature #9835
Comments
Here's a simple ScopeGuard implementation as a library: https://gist.github.com/sfackler/6965006. Having to manually save the object in a variable isn't great, but a syntax extension to do expand scope!(Success) { thing } to something like let __scope_<FILE>_<LINE>_<COL> = ::std::scope::scope(Success, { thing }); shouldn't be too hard. I don't think it can be done with a |
The original blocker for this was that closures didn't borrow their contents, so an implementation was unsound. The source of this unsoundness has been fixed, and this was attempted in #11905. The PR was abandoned because the borrowing became too unmanageable (prevented too many legitimate situations). A new effort may uncover something different, and this may need to be a language feature rather than a library if we do indeed add it. |
This issue is a feature request, and needs an approved RFC to be implemented. It should be moved to the rust-lang/rfcs repo. (As per the issues policy) cc @nick29581 |
This issue has been moved to the RFCs repo: rust-lang/rfcs#394 |
Avoid linting unsized mutable reference fix rust-lang/rust-clippy#9035 changelog: [`mut_mut`] avoid suggesting to reborrow unsized mutable reference
http://dlang.org/statement.html#ScopeGuardStatement
The text was updated successfully, but these errors were encountered: