Skip to content

Commit

Permalink
Rollup merge of rust-lang#71480 - GuillaumeGomez:panic-info-example, …
Browse files Browse the repository at this point in the history
…r=Dylan-DPC

Improve PanicInfo examples readability

cc @Eijebong

r? @Dylan-DPC
  • Loading branch information
Dylan-DPC authored Apr 24, 2020
2 parents 336a0c3 + 03817ec commit 440d600
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/libcore/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ impl<'a> PanicInfo<'a> {
/// 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");
Expand Down Expand Up @@ -112,8 +116,10 @@ impl<'a> PanicInfo<'a> {
///
/// panic::set_hook(Box::new(|panic_info| {
/// if let Some(location) = panic_info.location() {
/// println!("panic occurred in file '{}' at line {}", location.file(),
/// location.line());
/// println!("panic occurred in file '{}' at line {}",
/// location.file(),
/// location.line(),
/// );
/// } else {
/// println!("panic occurred but can't get location information...");
/// }
Expand Down

0 comments on commit 440d600

Please sign in to comment.