Skip to content
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

Closed
thestinger opened this issue Oct 13, 2013 · 4 comments
Closed

implement scope guards, as a syntax ext or language feature #9835

thestinger opened this issue Oct 13, 2013 · 4 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@thestinger
Copy link
Contributor

http://dlang.org/statement.html#ScopeGuardStatement

@sfackler
Copy link
Member

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 macro_rules currently.

@alexcrichton
Copy link
Member

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.

@japaric
Copy link
Member

japaric commented Oct 14, 2014

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

@rust-highfive
Copy link
Collaborator

This issue has been moved to the RFCs repo: rust-lang/rfcs#394

flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 21, 2022
Avoid linting unsized mutable reference

fix rust-lang/rust-clippy#9035

changelog: [`mut_mut`] avoid suggesting to reborrow unsized mutable reference
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

5 participants