Skip to content

Commit d2fb2fb

Browse files
committed
Avoid unwrapping in PanicInfo doc example.
Fixes #51768.
1 parent b9f1a07 commit d2fb2fb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/libcore/panic.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ use fmt;
3030
/// use std::panic;
3131
///
3232
/// panic::set_hook(Box::new(|panic_info| {
33-
/// println!("panic occurred: {:?}", panic_info.payload().downcast_ref::<&str>().unwrap());
33+
/// if let Some(s) = panic_info.payload().downcast_ref::<&str>() {
34+
/// println!("panic occurred: {:?}", s);
35+
/// } else {
36+
/// println!("panic occurred");
37+
/// }
3438
/// }));
3539
///
3640
/// panic!("Normal panic");

0 commit comments

Comments
 (0)