-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a custom panic message for resuming
gen
blocks after they panicked
- Loading branch information
Showing
4 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|