File tree 4 files changed +40
-2
lines changed
4 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ middle_assert_coroutine_resume_after_return = coroutine resumed after completion
12
12
middle_assert_divide_by_zero =
13
13
attempt to divide `{ $val } ` by zero
14
14
15
+ middle_assert_gen_resume_after_panic = `gen` fn or block cannot be further iterated on after it panicked
16
+
15
17
middle_assert_misaligned_ptr_deref =
16
18
misaligned pointer dereference: address must be a multiple of { $required } but is { $found }
17
19
Original file line number Diff line number Diff line change @@ -250,8 +250,7 @@ impl<O> AssertKind<O> {
250
250
middle_assert_coroutine_resume_after_return
251
251
}
252
252
ResumedAfterPanic ( CoroutineKind :: Async ( _) ) => middle_assert_async_resume_after_panic,
253
- // FIXME(gen_blocks): custom error message for `gen` blocks
254
- ResumedAfterPanic ( CoroutineKind :: Gen ( _) ) => middle_assert_async_resume_after_panic,
253
+ ResumedAfterPanic ( CoroutineKind :: Gen ( _) ) => middle_assert_gen_resume_after_panic,
255
254
ResumedAfterPanic ( CoroutineKind :: Coroutine ) => {
256
255
middle_assert_coroutine_resume_after_panic
257
256
}
Original file line number Diff line number Diff line change
1
+ //compile-flags: --edition 2024 -Zunstable-options
2
+ // run-pass
3
+ #![ feature( gen_blocks) ]
4
+
5
+ fn main ( ) {
6
+ let mut iter = gen {
7
+ yield 42 ;
8
+ panic ! ( "foo" ) ;
9
+ yield 69 ; //~ WARN: unreachable statement
10
+ } ;
11
+ assert_eq ! ( iter. next( ) , Some ( 42 ) ) ;
12
+ let mut tmp = std:: panic:: AssertUnwindSafe ( & mut iter) ;
13
+ match std:: panic:: catch_unwind ( move || tmp. next ( ) ) {
14
+ Ok ( _) => unreachable ! ( ) ,
15
+ Err ( err) => assert_eq ! ( * err. downcast:: <& ' static str >( ) . unwrap( ) , "foo" ) ,
16
+ }
17
+
18
+ match std:: panic:: catch_unwind ( move || iter. next ( ) ) {
19
+ Ok ( _) => unreachable ! ( ) ,
20
+ Err ( err) => assert_eq ! (
21
+ * err. downcast:: <& ' static str >( ) . unwrap( ) ,
22
+ "`gen fn` should just keep returning `None` after panicking" ,
23
+ ) ,
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ warning: unreachable statement
2
+ --> $DIR/gen_block_panic.rs:9:9
3
+ |
4
+ LL | panic!("foo");
5
+ | ------------- any code following this expression is unreachable
6
+ LL | yield 69;
7
+ | ^^^^^^^^^ unreachable statement
8
+ |
9
+ = note: `#[warn(unreachable_code)]` on by default
10
+
11
+ warning: 1 warning emitted
12
+
You can’t perform that action at this time.
0 commit comments