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 |
|
@bors r+ rollup |
…on, r=Mark-Simulacrum core: fix the docs of PanicInfo::location After `core::panic::PanicInfo` and `std::panic::PanicHookInfo` [were split](rust-lang#115974), 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 behavior 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. Addresses: rust-lang#128788 @rustbot label +A-docs r? libs
Rollup of 18 pull requests Successful merges: - #158102 (When compiling without a specified `--edition`, emit a message) - #162027 (std: add `fs::rename_noreplace`) - #162761 (Lower attributes for functions without bodies) - #163161 (implement FCW for `rustc_allowed_through_unstable_modules` items) - #163613 (Tweak the rendering of "not general enough" errors on the old trait solver) - #162062 (core: fix the docs of PanicInfo::location) - #163140 (document safety requirements for atomic intrinsics) - #163342 (Don't imply incorrect things about `Global` in the docs of `System`) - #163445 (Add safety comments for alloc::str) - #163503 (Mark Rc strong/weak count methods must_use) - #163548 (fs::set_permissions_nofollow: Android support, test cleanup) - #163585 ([triagebot] Create `debugger_visualizer` assign group) - #163597 (Add `SplitPathsRef` implementation for motor to make std build) - #163602 (Move media & home dirs tests to fs tests.) - #163667 (Finalize changes on expect messages for library/core/src/fmt/mod.rs) - #163682 ([rustdoc] Correctly link to (imported) enum variants with "jump to def") - #163683 (Fix GCC codegen backend comment in bootstrap) - #163703 (Move more `rustdoc-html tests` in the right location) Failed merges: - #161491 (Rip out old solver coherence)
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