You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, this causes:
error[E0515]: cannot yield value referencing local variable buf
I don't see a reason why the compiler couldn't track that lifetime like it does when returning references to self from synchronous functions. As long as you want to use the return value, you'd simply not be allowed to call resume() since you'd need a reference to the generator for that.
Admittedly it'd currently be impossible (to my knowledge) to write a reference-yielding Generator manually by implementing the trait since you can't specify the lifetimes properly. It might be possible using GAT but afaik that'd require a change to the signature of the Generator trait.
The text was updated successfully, but these errors were encountered:
Admittedly it'd currently be impossible (to my knowledge) to write a reference-yielding Generator manually by implementing the trait since you can't specify the lifetimes properly.
I think this is exactly why this is an issue. Generators just lower down to special objects that implement the Generator trait -- there's no way to express this lifetime relationship, since the yield type of a generator cannot capture the lifetime of the self passed in.
Consider this:
Currently, this causes:
error[E0515]: cannot yield value referencing local variable
buf
I don't see a reason why the compiler couldn't track that lifetime like it does when returning references to
self
from synchronous functions. As long as you want to use the return value, you'd simply not be allowed to callresume()
since you'd need a reference to the generator for that.Admittedly it'd currently be impossible (to my knowledge) to write a reference-yielding Generator manually by implementing the trait since you can't specify the lifetimes properly. It might be possible using GAT but afaik that'd require a change to the signature of the Generator trait.
The text was updated successfully, but these errors were encountered: