about summary refs log tree commit diff
path: root/src/libcore/panic.rs
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2018-07-10 22:25:38 -0400
committerCorey Farwell <coreyf@rwell.org>2018-07-10 22:25:38 -0400
commitd2fb2fb2a5f58839eda54e5f347e0959ed6eec7c (patch)
treec2d333e3499114715d4811aff632f7a401532510 /src/libcore/panic.rs
parentb9f1a0762a7c08c71f485fa4b152ed2477b07560 (diff)
downloadrust-d2fb2fb2a5f58839eda54e5f347e0959ed6eec7c.tar.gz
rust-d2fb2fb2a5f58839eda54e5f347e0959ed6eec7c.zip
Avoid unwrapping in PanicInfo doc example.
Fixes https://github.com/rust-lang/rust/issues/51768.
Diffstat (limited to 'src/libcore/panic.rs')
-rw-r--r--src/libcore/panic.rs6
1 files changed, 5 insertions, 1 deletions
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 fmt;
 /// 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");