Files
rust/tests/coverage/iffy/coroutine.rs
Zalathar c7c0eeaa3a Move some less-useful tests into tests/coverage/iffy
These tests are of limited value for investigating specific problems, but still
have some worth in detecting regressions by adding variety to the test corpus.

(The boundary is a bit fuzzy, but it's easy enough to move tests back out if
appropriate.)
2026-09-04 16:20:03 +10:00

37 lines
1.1 KiB
Rust

//@ min-llvm-version: 23
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
use std::ops::{Coroutine, CoroutineState};
use std::pin::Pin;
// The following implementation of a function called from a `yield` statement
// (apparently requiring the Result and the `String` type or constructor)
// creates conditions where the `coroutine::StateTransform` MIR transform will
// drop all `Counter` `Coverage` statements from a MIR. `simplify.rs` has logic
// to handle this condition, and still report dead block coverage.
fn get_u32(val: bool) -> Result<u32, String> {
if val {
Ok(1) //
} else {
Err(String::from("some error")) //
}
}
fn main() {
let is_true = std::env::args().len() == 1;
let mut coroutine = #[coroutine]
|| {
yield get_u32(is_true);
return "foo";
};
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Yielded(Ok(1)) => {}
_ => panic!("unexpected return from resume"),
}
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Complete("foo") => {}
_ => panic!("unexpected return from resume"),
}
}