From d2fb2fb2a5f58839eda54e5f347e0959ed6eec7c Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 10 Jul 2018 22:25:38 -0400 Subject: [PATCH] Avoid unwrapping in PanicInfo doc example. Fixes https://github.com/rust-lang/rust/issues/51768. --- src/libcore/panic.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libcore/panic.rs b/src/libcore/panic.rs index 1b4129b99fc..10f02ca2fdc 100644 --- a/src/libcore/panic.rs +++ b/src/libcore/panic.rs @@ -30,7 +30,11 @@ /// use std::panic; /// /// panic::set_hook(Box::new(|panic_info| { -/// println!("panic occurred: {:?}", panic_info.payload().downcast_ref::<&str>().unwrap()); +/// if let Some(s) = panic_info.payload().downcast_ref::<&str>() { +/// println!("panic occurred: {:?}", s); +/// } else { +/// println!("panic occurred"); +/// } /// })); /// /// panic!("Normal panic"); -- 2.44.0