2024-01-03 19:46:43 -06:00
|
|
|
#![feature(coroutine_trait)]
|
|
|
|
#![feature(coroutines)]
|
|
|
|
|
|
|
|
use std::ops::Coroutine;
|
|
|
|
|
|
|
|
struct Contravariant<'a>(fn(&'a ()));
|
|
|
|
struct Covariant<'a>(fn() -> &'a ());
|
|
|
|
|
|
|
|
fn bad1<'short, 'long: 'short>() -> impl Coroutine<Covariant<'short>> {
|
2024-04-11 08:15:34 -05:00
|
|
|
#[coroutine] |_: Covariant<'short>| {
|
2024-01-03 19:46:43 -06:00
|
|
|
let a: Covariant<'long> = yield ();
|
|
|
|
//~^ ERROR lifetime may not live long enough
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bad2<'short, 'long: 'short>() -> impl Coroutine<Contravariant<'long>> {
|
2024-04-11 08:15:34 -05:00
|
|
|
#[coroutine] |_: Contravariant<'long>| {
|
2024-01-03 19:46:43 -06:00
|
|
|
let a: Contravariant<'short> = yield ();
|
|
|
|
//~^ ERROR lifetime may not live long enough
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn good1<'short, 'long: 'short>() -> impl Coroutine<Covariant<'long>> {
|
2024-04-11 08:15:34 -05:00
|
|
|
#[coroutine] |_: Covariant<'long>| {
|
2024-01-03 19:46:43 -06:00
|
|
|
let a: Covariant<'short> = yield ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn good2<'short, 'long: 'short>() -> impl Coroutine<Contravariant<'short>> {
|
2024-04-11 08:15:34 -05:00
|
|
|
#[coroutine] |_: Contravariant<'short>| {
|
2024-01-03 19:46:43 -06:00
|
|
|
let a: Contravariant<'long> = yield ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|