Avoid unwrapping in PanicInfo doc example.

Fixes https://github.com/rust-lang/rust/issues/51768.
This commit is contained in:
Corey Farwell 2018-07-10 22:25:38 -04:00
parent b9f1a0762a
commit d2fb2fb2a5

View File

@ -30,7 +30,11 @@ use fmt;
/// use std::panic; /// use std::panic;
/// ///
/// panic::set_hook(Box::new(|panic_info| { /// 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"); /// panic!("Normal panic");