mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 10:45:18 +00:00
9dc6e08279
Currently we can't automatically enforce formatting on tests (see #125637), but we can at least keep things relatively tidy by occasionally running the formatter manually. This was done by temporarily commenting out the `"/tests/"` exclusion in `rustfmt.toml`, and then running `x fmt tests/coverage` and `x test coverage --bless`.
40 lines
989 B
Rust
40 lines
989 B
Rust
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
|
|
#![allow(unused_assignments)]
|
|
|
|
use std::ops::{Coroutine, CoroutineState};
|
|
use std::pin::Pin;
|
|
|
|
fn main() {
|
|
let mut coroutine = #[coroutine]
|
|
|| {
|
|
yield 1;
|
|
return "foo";
|
|
};
|
|
|
|
match Pin::new(&mut coroutine).resume(()) {
|
|
CoroutineState::Yielded(1) => {}
|
|
_ => panic!("unexpected value from resume"),
|
|
}
|
|
match Pin::new(&mut coroutine).resume(()) {
|
|
CoroutineState::Complete("foo") => {}
|
|
_ => panic!("unexpected value from resume"),
|
|
}
|
|
|
|
let mut coroutine = #[coroutine]
|
|
|| {
|
|
yield 1;
|
|
yield 2;
|
|
yield 3;
|
|
return "foo";
|
|
};
|
|
|
|
match Pin::new(&mut coroutine).resume(()) {
|
|
CoroutineState::Yielded(1) => {}
|
|
_ => panic!("unexpected value from resume"),
|
|
}
|
|
match Pin::new(&mut coroutine).resume(()) {
|
|
CoroutineState::Yielded(2) => {}
|
|
_ => panic!("unexpected value from resume"),
|
|
}
|
|
}
|