summary refs log tree commit diff
path: root/tests/ui/coroutine/check-resume-ty-lifetimes.rs
blob: b75e46c541cc5f91a8119700d79fb2ccf5613962 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#![feature(coroutine_trait)]
#![feature(coroutines, stmt_expr_attributes)]
#![allow(unused)]

use std::ops::Coroutine;
use std::ops::CoroutineState;
use std::pin::pin;

fn mk_static(s: &str) -> &'static str {
    let mut storage: Option<&'static str> = None;

    let mut coroutine = pin!(
        #[coroutine]
        |_: &str| {
            let x: &'static str = yield ();
            //~^ ERROR lifetime may not live long enough
            storage = Some(x);
        }
    );

    coroutine.as_mut().resume(s);
    coroutine.as_mut().resume(s);

    storage.unwrap()
}

fn main() {
    let s = mk_static(&String::from("hello, world"));
    println!("{s}");
}