-
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
Conversation
Having a section for this inspired by the docs for array::IntoIterator
For most things in the stdlib, there's the rustdoc-generated version annotations. I don't think we can do this here, so just write prose. I have tried to be as terse as possible while still noting the relevant gotchas.
That xref contains the actual documentation for what format! does. It should be very prominent - particularly, more so than the other links.
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @scottmcm (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
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.
Thanks for sending the PR! I like the approach of sending things consistently to the module documentation, rather than to the various macros.
Please address the various comments -- either with changes or with prose saying why you disagree -- then mark the PR as ready for review again with @rustbot ready
.
@@ -84,6 +84,7 @@ | |||
//! | |||
//! If a named parameter does not appear in the argument list, `format!` will | |||
//! reference a variable with that name in the current scope. | |||
//! (Rust 1.58 and later; in [`panic!`], requires Rust 2021.) |
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.
//! (Rust 1.58 and later; in [`panic!`], requires Rust 2021.) |
@@ -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 comment
The 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,
# Editions
## 2021 and later
... `panic!` always uses formatting; use `panic_any` if you want a value ...
## 2018 and 2015
... panics with a payload of literally ...
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: maybe just say
the [`format!` syntax]. That payload is used when injecting the panic into | |
the [formatting syntax]. That payload is used when injecting the panic into |
rather that mentioning a particular macro? That avoids a conversation about whether it's "the format!
syntax" or "the format_args!
syntax" or ...
ping from triage: |
Document panic behavior across editions, and improve xrefs This revives (parts of) rust-lang#96518. r? `@scottmcm` Cc `@ijackson`
This MR addresses three somewhat-related issues:
panic!
did not document the 2021 edition differences.format!
(instd::fmt
) did not document the version requirement for implicit capture.format!
(instd::fmt
) were badly referenced. Somehow every time I wanted them I ended up informat_args!
or somewhere, clicking round in circles...