Skip to content

Commit c3d8236

Browse files
Rollup merge of #52238 - frewsxcv:frewsxcv-unwrap, r=GuillaumeGomez
Avoid unwrapping in PanicInfo doc example. Fixes #51768.
2 parents c202dfe + d2fb2fb commit c3d8236

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)