rust/tests/ui/coroutine/issue-44197.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
772 B
Rust
Raw Normal View History

//@ run-pass
2023-10-19 21:46:28 +00:00
#![feature(coroutines, coroutine_trait)]
2023-10-19 16:06:43 +00:00
use std::ops::{Coroutine, CoroutineState};
2018-10-04 18:49:38 +00:00
use std::pin::Pin;
fn foo(_: &str) -> String {
String::new()
}
2023-10-19 16:06:43 +00:00
fn bar(baz: String) -> impl Coroutine<(), Yield = String, Return = ()> {
#[coroutine] move || {
yield foo(&baz);
}
}
fn foo2(_: &str) -> Result<String, ()> {
Err(())
}
2023-10-19 16:06:43 +00:00
fn bar2(baz: String) -> impl Coroutine<(), Yield = String, Return = ()> {
#[coroutine] move || {
if let Ok(quux) = foo2(&baz) {
yield quux;
}
}
}
fn main() {
assert_eq!(
Pin::new(&mut bar(String::new())).resume(()),
2023-10-19 16:06:43 +00:00
CoroutineState::Yielded(String::new())
);
2023-10-19 16:06:43 +00:00
assert_eq!(Pin::new(&mut bar2(String::new())).resume(()), CoroutineState::Complete(()));
}