rust/tests/ui/coroutine/gen_block_panic.rs
2023-10-30 16:32:53 +00:00

27 lines
785 B
Rust

//compile-flags: --edition 2024 -Zunstable-options
// run-pass
// needs-unwind
#![feature(gen_blocks)]
fn main() {
let mut iter = gen {
yield 42;
panic!("foo");
yield 69; //~ WARN: unreachable statement
};
assert_eq!(iter.next(), Some(42));
let mut tmp = std::panic::AssertUnwindSafe(&mut iter);
match std::panic::catch_unwind(move || tmp.next()) {
Ok(_) => unreachable!(),
Err(err) => assert_eq!(*err.downcast::<&'static str>().unwrap(), "foo"),
}
match std::panic::catch_unwind(move || iter.next()) {
Ok(_) => unreachable!(),
Err(err) => assert_eq!(
*err.downcast::<&'static str>().unwrap(),
"`gen fn` should just keep returning `None` after panicking",
),
}
}