Description
With #68524, the Coroutine
trait has gained a type parameter for the resume argument. Currently, this parameter will not be inferred to a type with late-bound regions. In some cases, this is required for soundness. For example, this coroutine stores the resume argument across a yield
, which means that it can not accept arbitrary lifetimes in it:
let coro = |arg: &mut bool| {
yield ();
*arg = true;
};
This coroutine ends up implementing Coroutine<&'x mut bool>
with a specific 'x
, not for<'x> Generator<&'x mut bool>
.
However, if the resume argument doesn't get stored inside the generator state, it should be fine for the coroutine to implement for<'x> Coroutine<&'x mut bool>
instead.
This is already how closures behave, since they can also store their arguments inside upvars, so it shouldn't be terribly difficult to extend this to coroutines. It would be good to come up with lots of test cases beforehand though (perhaps inspired by the tests for closures).