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

Allow to forget about borrowing outside scoping #36422

Closed
uzytkownik opened this issue Sep 12, 2016 · 4 comments
Closed

Allow to forget about borrowing outside scoping #36422

uzytkownik opened this issue Sep 12, 2016 · 4 comments
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug.

Comments

@uzytkownik
Copy link

It's more of a paper cut but I find it tedious to write code in following fashion:

let (foo, bar, almost_all_variables) = {
     let foobar = borrow_some_variable;
     let foo = borrow_some_variable.foo();
     let bar = borrow_some_variable.bar();
     ...
     (foo, bar, almost_all_variables)
};
// Here I cannot have a borrowed variable
let (foobar, ....) = {

I would prefer to have something like:

let foobar = borrow_some_variable;
let foo = borrow_some_variable.foo();
let bar = borrow_some_variable.bar();
...
forger foobar;
// We behave as if we exited scope of foobar and all dependent variables but with autoexport of them

Or at least some syntax sugar over the top:

scoped! {
     let foobar = borrow_some_variable;
     outer!(let foo = borrow_some_variable.foo()); // Export to outer scop
     outer!(let bar = borrow_some_variable.bar());
};
@durka
Copy link
Contributor

durka commented Sep 12, 2016

This is covered under "non-lexical lifetimes" -- once those are implemented, then drop(foobar); where foobar is a reference will work. See http://smallcultfollowing.com/babysteps/blog/2016/04/27/non-lexical-lifetimes-introduction/

@hanna-kruppe
Copy link
Contributor

Part of rust-lang/rfcs#811

@Thiez
Copy link
Contributor

Thiez commented Sep 15, 2016

This is covered under "non-lexical lifetimes" -- once those are implemented, then drop(foobar); where foobar is a reference will work. See http://smallcultfollowing.com/babysteps/blog/2016/04/27/non-lexical-lifetimes-introduction/

Surely that would only work for &mut T references, since &T references are Copy?

@Mark-Simulacrum Mark-Simulacrum added the A-NLL Area: Non-lexical lifetimes (NLL) label May 13, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 26, 2017
@nikomatsakis
Copy link
Contributor

I'm going to close this as "the basic point of NLL" -- it seems like too general of a bug report to be actionable just now. @uzytkownik, if you like you may experiment with NLL by doing #![feature(nll)], and if you encounter problems, please do file issues! =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

6 participants