From: Corey Farwell Date: Wed, 11 Jul 2018 02:25:38 +0000 (-0400) Subject: Avoid unwrapping in PanicInfo doc example. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=d2fb2fb2a5f58839eda54e5f347e0959ed6eec7c;p=rust.git Avoid unwrapping in PanicInfo doc example. Fixes https://github.com/rust-lang/rust/issues/51768. --- 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");