]> git.lizzy.rs Git - rust.git/commitdiff
Avoid unwrapping in PanicInfo doc example.
authorCorey Farwell <coreyf@rwell.org>
Wed, 11 Jul 2018 02:25:38 +0000 (22:25 -0400)
committerCorey Farwell <coreyf@rwell.org>
Wed, 11 Jul 2018 02:25:38 +0000 (22:25 -0400)
Fixes https://github.com/rust-lang/rust/issues/51768.

src/libcore/panic.rs

index 1b4129b99fc535bc8315c068bfe8f9ccb3b6d50b..10f02ca2fdc45cf8e06b291fa94070370729109a 100644 (file)
 /// 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");