core: fix the docs of PanicInfo::location - #162062
valentynkit wants to merge 3 commits into
Conversation
After `core::panic::PanicInfo` and `std::panic::PanicHookInfo` were split, the docs for `location` still showed incorrect usage of `std::panic::set_hook` for `core::panic::PanicInfo` location, leftover from before the split. Also notes for location methods of `PanicInfo` and `PanicHookInfo` were updated, explaining that if it is ever changed to return None, it should be addressed where the location is created and where it's unwrapped, to avoid unexpected behaviour when callers may expect to always receive location. For `PanicInfo`, `panic_fmt` builds it, and `panic_handler` unwraps it. For `PanicHookInfo`, `panic_with_hook` builds it, and `default_hook` unwraps it.
| /// ); | ||
| /// } else { | ||
| /// println!("panic occurred but can't get location information..."); | ||
| /// write!(DEBUG_OUTPUT, "panicked at {}", location); |
There was a problem hiding this comment.
I think a well-behaved panic handler would have an else branch here, so we shouldn't lose that. It should be uncommon to want no output printed for a future version of Rust that returned None.
There was a problem hiding this comment.
Thanks, added else branch, but using slightly different message than the original for this example in else branch, let me know if you would prefer to have the original line:
panic occurred but can't get location information...
There was a problem hiding this comment.
Can you update https://doc.rust-lang.org/nightly/std/panic/struct.PanicHookInfo.html#method.location to match/align the fallback string?
r=me with that done
|
@rustbot ready |
Use the same fallback string as the PanicInfo::location example in the PanicHookInfo::location and Location doc examples for consistency.
|
@rustbot ready also aligned the same string in the |
After
core::panic::PanicInfoandstd::panic::PanicHookInfowere split, the docs forlocationstill showed incorrect usage ofstd::panic::set_hookforcore::panic::PanicInfolocation, leftover from before the split.Also notes for location methods of
PanicInfoandPanicHookInfowere updated, explaining that if it is ever changed to return None, it should be addressed where the location is created and where it's unwrapped, to avoid unexpected behavior when callers may expect to always receive location.PanicInfo,panic_fmtbuilds it, andpanic_handlerunwraps it.PanicHookInfo,panic_with_hookbuilds it, anddefault_hookunwraps it.Addresses: #128788
@rustbot label +A-docs
r? libs