mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Add a custom panic message for resuming gen
blocks after they panicked
This commit is contained in:
parent
745c600617
commit
bc926f7c33
@ -12,6 +12,8 @@ middle_assert_coroutine_resume_after_return = coroutine resumed after completion
|
||||
middle_assert_divide_by_zero =
|
||||
attempt to divide `{$val}` by zero
|
||||
|
||||
middle_assert_gen_resume_after_panic = `gen` fn or block cannot be further iterated on after it panicked
|
||||
|
||||
middle_assert_misaligned_ptr_deref =
|
||||
misaligned pointer dereference: address must be a multiple of {$required} but is {$found}
|
||||
|
||||
|
@ -250,8 +250,7 @@ impl<O> AssertKind<O> {
|
||||
middle_assert_coroutine_resume_after_return
|
||||
}
|
||||
ResumedAfterPanic(CoroutineKind::Async(_)) => middle_assert_async_resume_after_panic,
|
||||
// FIXME(gen_blocks): custom error message for `gen` blocks
|
||||
ResumedAfterPanic(CoroutineKind::Gen(_)) => middle_assert_async_resume_after_panic,
|
||||
ResumedAfterPanic(CoroutineKind::Gen(_)) => middle_assert_gen_resume_after_panic,
|
||||
ResumedAfterPanic(CoroutineKind::Coroutine) => {
|
||||
middle_assert_coroutine_resume_after_panic
|
||||
}
|
||||
|
25
tests/ui/coroutine/gen_block_panic.rs
Normal file
25
tests/ui/coroutine/gen_block_panic.rs
Normal file
@ -0,0 +1,25 @@
|
||||
//compile-flags: --edition 2024 -Zunstable-options
|
||||
// run-pass
|
||||
#![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",
|
||||
),
|
||||
}
|
||||
}
|
12
tests/ui/coroutine/gen_block_panic.stderr
Normal file
12
tests/ui/coroutine/gen_block_panic.stderr
Normal file
@ -0,0 +1,12 @@
|
||||
warning: unreachable statement
|
||||
--> $DIR/gen_block_panic.rs:9:9
|
||||
|
|
||||
LL | panic!("foo");
|
||||
| ------------- any code following this expression is unreachable
|
||||
LL | yield 69;
|
||||
| ^^^^^^^^^ unreachable statement
|
||||
|
|
||||
= note: `#[warn(unreachable_code)]` on by default
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
Loading…
Reference in New Issue
Block a user