Skip to content

core: fix the docs of PanicInfo::location - #162062

Open
valentynkit wants to merge 3 commits into
rust-lang:mainfrom
valentynkit:docs/panic-info-location
Open

valentynkit wants to merge 3 commits into
rust-lang:mainfrom
valentynkit:docs/panic-info-location

Conversation

@valentynkit

@valentynkit valentynkit commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

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 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: #128788
@rustbot label +A-docs
r? libs

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.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools labels Aug 31, 2026
/// );
/// } else {
/// println!("panic occurred but can't get location information...");
/// write!(DEBUG_OUTPUT, "panicked at {}", location);

@Mark-Simulacrum Mark-Simulacrum Sep 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

@Mark-Simulacrum Mark-Simulacrum Sep 19, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 13, 2026
@valentynkit

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 15, 2026
@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 19, 2026
Use the same fallback string as the PanicInfo::location example
in the PanicHookInfo::location and Location doc examples for
consistency.
@valentynkit

Copy link
Copy Markdown
Contributor Author

@rustbot ready also aligned the same string in the Location examples.
There were 5 occurrences of fallback string in docs which were updated for consistency.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 27, 2026
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 4ce013c has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 3, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Oct 3, 2026
…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
rust-bors Bot pushed a commit that referenced this pull request Oct 4, 2026
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)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants