-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Clarify/fix formatting docs concerning fmt::Result/fmt::Error #35862
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
This kind of documentation is an indication that the API is designed wrongly. In particular, the user of the thing that implements In some cases, the implementation of |
@briansmith I agree it's not ideal but it's stable...
That's how it works currently. The point of the result is to tell caller that an error has occurred and that it should stop formatting. The actual error is stashed elsewhere. For example: impl Display for Something {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
Display::fmt(&self.message, f)?; // bail early on error
Display::fmt(&":", f)?; // bail early on error
Display::fmt(&self.detail, f)?;
}
}
If it's a bug (programmer error or variant violation), it should panic; that's the point of panic. However, if your Also, in this case, the error will just be dropped on the floor in trait implementations like |
Doing otherwise would break traits like `ToString`.
@briansmith is the updated documentation clear now? |
Yes, it is clearer. You might clarify it further by saying more of what you said in your comment above: "If any other kind of error could occur, that is a sign that |
@briansmith now that I actually pushed the change I was asking about... any better? |
Yes, it's clearer. |
👍 |
They're the same thing but it's better to keep the terminology consistent.
@bors: r+ rollup |
📌 Commit c7d5f7e has been approved by |
Clarify/fix formatting docs concerning fmt::Result/fmt::Error 1. `fmt::Result` != `io::Result<()>` 2. Formatters should only propagate errors, not return their own. Confusion on reddit: https://www.reddit.com/r/rust/comments/4yorxr/is_implt_tostring_for_t_where_t_display_sized_a/
Clarify/fix formatting docs concerning fmt::Result/fmt::Error 1. `fmt::Result` != `io::Result<()>` 2. Formatters should only propagate errors, not return their own. Confusion on reddit: https://www.reddit.com/r/rust/comments/4yorxr/is_implt_tostring_for_t_where_t_display_sized_a/
Clarify/fix formatting docs concerning fmt::Result/fmt::Error 1. `fmt::Result` != `io::Result<()>` 2. Formatters should only propagate errors, not return their own. Confusion on reddit: https://www.reddit.com/r/rust/comments/4yorxr/is_implt_tostring_for_t_where_t_display_sized_a/
Clarify/fix formatting docs concerning fmt::Result/fmt::Error 1. `fmt::Result` != `io::Result<()>` 2. Formatters should only propagate errors, not return their own. Confusion on reddit: https://www.reddit.com/r/rust/comments/4yorxr/is_implt_tostring_for_t_where_t_display_sized_a/
⌛ Testing commit c7d5f7e with merge d62f786... |
💔 Test failed - auto-mac-64-opt-rustbuild |
@bors retry |
Clarify/fix formatting docs concerning fmt::Result/fmt::Error 1. `fmt::Result` != `io::Result<()>` 2. Formatters should only propagate errors, not return their own. Confusion on reddit: https://www.reddit.com/r/rust/comments/4yorxr/is_implt_tostring_for_t_where_t_display_sized_a/
Clarify/fix formatting docs concerning fmt::Result/fmt::Error 1. `fmt::Result` != `io::Result<()>` 2. Formatters should only propagate errors, not return their own. Confusion on reddit: https://www.reddit.com/r/rust/comments/4yorxr/is_implt_tostring_for_t_where_t_display_sized_a/
Clarify/fix formatting docs concerning fmt::Result/fmt::Error 1. `fmt::Result` != `io::Result<()>` 2. Formatters should only propagate errors, not return their own. Confusion on reddit: https://www.reddit.com/r/rust/comments/4yorxr/is_implt_tostring_for_t_where_t_display_sized_a/
fmt::Result
!=io::Result<()>
Confusion on reddit: https://www.reddit.com/r/rust/comments/4yorxr/is_implt_tostring_for_t_where_t_display_sized_a/