-
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 proper usage of fmt::Error
and fmt()
's Result
.
#124954
Conversation
Documentation of these properties previously existed in a lone paragraph in the `fmt` module's documentation: <https://doc.rust-lang.org/1.78.0/std/fmt/index.html#formatting-traits> However, users looking to implement a formatting trait won't necessarily look there. Therefore, let's add the critical information (that formatting per se is infallible) to all the involved items.
r? @Nilstrieb rustbot has assigned @Nilstrieb. Use |
@bors r+ |
I wonder if this should be made into a panic then, since it can't be reached unless there's a bug in the formatter? |
that should indeed be unreachable unless someone has a fallible formatting impl. not sure whether it's worth panicking in that case though, maybe. |
We do panic in the equivalent case in |
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#124928 (Stabilize `byte_slice_trim_ascii` for `&[u8]`/`&str`) - rust-lang#124954 (Document proper usage of `fmt::Error` and `fmt()`'s `Result`.) - rust-lang#124969 (check if `x test tests` missing any test directory) - rust-lang#124978 (Handle Deref expressions in invalid_reference_casting) - rust-lang#125005 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#124954 - kpreid:fmterr, r=Nilstrieb Document proper usage of `fmt::Error` and `fmt()`'s `Result`. I've seen several newcomers wonder why `fmt::Error` doesn't have any error detail information, or propose to return it in response to an error condition found inside a `impl fmt::Display for MyType`. That is incorrect, per [a lone paragraph of the `fmt` module's documentation](https://doc.rust-lang.org/1.78.0/std/fmt/index.html#formatting-traits). However, users looking to implement a formatting trait won't necessarily look there. Therefore, let's add the critical information (that formatting per se is infallible) to all the involved items: every `fmt()` method, and `fmt::Error`. This PR is not intended to make any novel claims about `fmt`; only to repeat an existing one in places where it will be more visible.
This comment was marked as outdated.
This comment was marked as outdated.
…crum,workingjubilee io::Write::write_fmt: panic if the formatter fails when the stream does not fail Follow-up to rust-lang#124954
…ingjubilee io::Write::write_fmt: panic if the formatter fails when the stream does not fail Follow-up to rust-lang/rust#124954
I've seen several newcomers wonder why
fmt::Error
doesn't have any error detail information, or propose to return it in response to an error condition found inside aimpl fmt::Display for MyType
.That is incorrect, per a lone paragraph of the
fmt
module's documentation. However, users looking to implement a formatting trait won't necessarily look there. Therefore, let's add the critical information (that formatting per se is infallible) to all the involved items: everyfmt()
method, andfmt::Error
.This PR is not intended to make any novel claims about
fmt
; only to repeat an existing one in places where it will be more visible.