2023-10-30 05:23:57 -05:00
|
|
|
//compile-flags: --edition 2024 -Zunstable-options
|
|
|
|
// run-pass
|
2023-10-30 11:05:25 -05:00
|
|
|
// needs-unwind
|
2023-10-30 05:23:57 -05:00
|
|
|
#![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",
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|