Document proper usage of fmt::Error and fmt()'s Result.#124954
Merged
bors merged 1 commit intorust-lang:masterfrom May 11, 2024
Merged
Document proper usage of fmt::Error and fmt()'s Result.#124954bors merged 1 commit intorust-lang:masterfrom
fmt::Error and fmt()'s Result.#124954bors merged 1 commit intorust-lang:masterfrom
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.
Collaborator
|
r? @Nilstrieb rustbot has assigned @Nilstrieb. Use |
Member
|
@bors r+ |
Collaborator
Member
|
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? |
Member
|
that should indeed be unreachable unless someone has a fallible formatting impl. not sure whether it's worth panicking in that case though, maybe. |
Member
|
We do panic in the equivalent case in |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 11, 2024
…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
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 11, 2024
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.
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 12, 2024
…crum,workingjubilee io::Write::write_fmt: panic if the formatter fails when the stream does not fail Follow-up to rust-lang#124954
RalfJung
pushed a commit
to RalfJung/miri
that referenced
this pull request
May 12, 2024
…ingjubilee io::Write::write_fmt: panic if the formatter fails when the stream does not fail Follow-up to rust-lang/rust#124954
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've seen several newcomers wonder why
fmt::Errordoesn'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
fmtmodule'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.