-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Borrow error when yielding with nested generators #45093
Comments
This could be a bug that rustc is pointing out a wrong |
The let result = sub_generator.resume();
match result {
GeneratorState::Yielded(x) => {
yield x;
}
_ => panic!("unexpected value from resume"),
} |
I see. Is this somewhat related to #44100 ? I guess that the borrow checker could have narrowed the borrowing to the matched value. |
@da-x No, it's the fault of the code which finds out which values could be stored in the generator. |
Duplicate of #44197 ? |
…ws across suspension points to borrowck. Fixes rust-lang#44197, rust-lang#45259 and rust-lang#45093.
Immovable generators This adds support for immovable generators which allow you to borrow local values inside generator across suspension points. These are declared using a `static` keyword: ```rust let mut generator = static || { let local = &Vec::new(); yield; local.push(0i8); }; generator.resume(); // ERROR moving the generator after it has resumed would invalidate the interior reference // drop(generator); ``` Region inference is no longer affected by the types stored in generators so the regions inside should be similar to other code (and unaffected by the presence of `yield` expressions). The borrow checker is extended to pick up the slack so interior references still result in errors for movable generators. This fixes #44197, #45259 and #45093. This PR depends on [PR #44917 (immovable types)](#44917), I suggest potential reviewers ignore the first commit as it adds immovable types.
Fixed by #45337. |
Hi, I got some feedback regarding the generator feature that is currently in nightly.
I am testing whether it is possible to yield out of a generator while another generator is in scope, for example:
However I am getting:
rustc:
rustc 1.22.0-nightly (05cbece09 2017-10-06)
I am not sure what borrow this error is talking about.
Is
sub_generator
not owned?Is there an intention to support such use cases?
The text was updated successfully, but these errors were encountered: