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

Generators can't have HRTBs on resume argument. #69300

Closed
kyren opened this issue Feb 19, 2020 · 3 comments
Closed

Generators can't have HRTBs on resume argument. #69300

kyren opened this issue Feb 19, 2020 · 3 comments

Comments

@kyren
Copy link
Contributor

kyren commented Feb 19, 2020

It seems as though it's not possible currently to write a generator that satisfies this bound:

fn accept<G: for<'a> Generator<&'a ()>>(g: G) {}

Trying something like this:

accept(|r| {
    let r = yield;
});

Gives:

5  | fn accept<G>(g: G)
   |    ------
6  | where
7  |     G: for<'a> Generator<&'a ()>,
   |        ------------------------- required by this bound in `accept`
...
12 |     accept(|r| {
   |     ^^^^^^
   |     |
   |     expected signature of `for<'a> fn(&'a ()) -> _`
   |     found signature of `fn(_) -> _`

I realize that generators are very unstable right now so I doubt this is high priority, but hopefully something like this could work eventually? I think it might be useful for generators to accept something like a temporary buffer as a resume argument that should only be valid until the next call to yield.

Incidentally, I didn't run into this problem legitimately, I ran into it trying to abuse generators to enable automatic garbage collection ala https://github.com/kyren/gc-arena, but I think that there are also valid reasons to want this to work as well 😛

@jonas-schievink
Copy link
Contributor

Yeah, this would be nice to have. This seems like a duplicate of #68923 though, so closing in favor of that.

@kyren
Copy link
Contributor Author

kyren commented Feb 19, 2020

Shoot, sorry for the duplicate, I even looked for it and asked on matrix beforehand, my search skills are bad!

@jonas-schievink
Copy link
Contributor

No worries!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants