-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document panic and format edition/verions, and improve xrefs #96518
Changes from all commits
c513b0d
562c89c
1720711
243f177
58b0ab5
bd0f059
8be3d46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,7 +9,7 @@ tests. `panic!` is closely tied with the `unwrap` method of both | |||||
`panic!` when they are set to [`None`] or [`Err`] variants. | ||||||
|
||||||
When using `panic!()` you can specify a string payload, that is built using | ||||||
the [`format!`] syntax. That payload is used when injecting the panic into | ||||||
the [`format!` syntax]. That payload is used when injecting the panic into | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: maybe just say
Suggested change
rather that mentioning a particular macro? That avoids a conversation about whether it's "the |
||||||
the calling Rust thread, causing the thread to panic entirely. | ||||||
|
||||||
The behavior of the default `std` hook, i.e. the code that runs directly | ||||||
|
@@ -55,7 +55,7 @@ For more detailed information about error handling check out the [book] or the | |||||
[`panic_any`]: ../std/panic/fn.panic_any.html | ||||||
[`Box`]: ../std/boxed/struct.Box.html | ||||||
[`Any`]: crate::any::Any | ||||||
[`format!`]: ../std/macro.format.html | ||||||
[`format!` syntax]: ../std/fmt/index.html | ||||||
[book]: ../book/ch09-00-error-handling.html | ||||||
[`std::result`]: ../std/result/index.html | ||||||
|
||||||
|
@@ -64,6 +64,25 @@ For more detailed information about error handling check out the [book] or the | |||||
If the main thread panics it will terminate all your threads and end your | ||||||
program with code `101`. | ||||||
|
||||||
# Editions | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, having this written out here is really handy 👍 One request: Can you put the information about the newest edition first in this section? We want to optimize the docs for people using the latest edition, and have people still using older ones need to scan down to find their behaviour, rather than having people using 2021 need to hunt. Maybe it could work well to make subsections here? Sketch,
|
||||||
|
||||||
In Rust Editions prior to 2021, `std::panic!(x)` with a single | ||||||
argument is equivalent to | ||||||
[`std::panic::panic_any(x)`](../std/panic/fn.panic_any.html). | ||||||
This is true even if the argument is a string literal. | ||||||
|
||||||
For example, in Rust 2015 `panic!("problem: {reason}")` panics with a | ||||||
payload of literally `"problem: {reason}"` (a `&'static str`), which | ||||||
is probably not what was intended. In current Rust this usage | ||||||
captures and formats a variable `reason` from the surrounding scope. | ||||||
|
||||||
In Rust editions prior to 2021, `core::panic!(x)` requires that | ||||||
`x` be `&str`, but does not require it to be a literal. In Rust 2021, | ||||||
these cases must be written `panic!("{}", x)`. | ||||||
|
||||||
In Rust 2021 and later, `panic!` always requires a format string and | ||||||
the applicable format arguments, and is the same in `core` and `std`. | ||||||
|
||||||
# Examples | ||||||
|
||||||
```should_panic | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this line. We don't include version numbers in the docs for every difference -- we host versioned copies of the docs (like https://doc.rust-lang.org/1.57.0/std/macro.format.html) so people using a particular version can see what that version supports. And we don't need to document
panic!
's edition behaviour here -- that's fine just in its own documentation.