Skip to content
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

std::fmt::Write methods error documentation #98861

Closed
yoav-lavi opened this issue Jul 3, 2022 · 8 comments
Closed

std::fmt::Write methods error documentation #98861

yoav-lavi opened this issue Jul 3, 2022 · 8 comments
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@yoav-lavi
Copy link
Contributor

yoav-lavi commented Jul 3, 2022

Location

std::fmt::Write

Summary

While opening this issue for Clippy, I noticed that many of the write_xyz methods have the following error description:

Errors

This function will return an instance of Error on error.

While I understand that this is due to the description being general for any implementation, this can seem tautological to someone that's not familiar with these methods and I thought perhaps it'd make sense to expand this a bit and add common scenarios / scenarios implemented by the standard library.

write_fmt seems to be missing this description in general.

Thank you!

@yoav-lavi yoav-lavi added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Jul 3, 2022
@vincenzopalazzo
Copy link
Member

@rustbot label +T-docs-rs +E-easy

@rustbot rustbot added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-docs-rs Relevant to the docs-rs subteam, which will review and decide on the PR/issue. labels Jul 3, 2022
@obeis obeis removed their assignment Jul 6, 2022
@fprasx
Copy link
Contributor

fprasx commented Jul 14, 2022

Hi, I've been looking into this and I can't find an actual implementation of the Write trait. All I can find is implementations for types that contain a dyn Write already. Seems kinda like a chicken and egg problem, I can only find impl's when the trait has already been implemented. I looked at mod.rs for core::fmt, and all the impl's were chicken-eggy. Does anybody who knows more about this know where I could look to find an actual implementation? If you point me in the right place, I'd be hapy to submit a pull improving the docs :)

@Havvy
Copy link
Contributor

Havvy commented Jul 14, 2022

The implementors section shows that String and Formatter<'_> implement the trait. Neither implementation returns the error directly though.

@GuillaumeGomez GuillaumeGomez removed the T-docs-rs Relevant to the docs-rs subteam, which will review and decide on the PR/issue. label Jul 21, 2022
@thedanvail
Copy link
Contributor

Would it be fair to have the docs say something along the lines of:

This function will return an instance of [`Error`] on error.

Though it is possible for implementors of this trait to return an error, at the time of writing these docs, no implementation of [`std::fmt::Write`] in the standard library returns such an error.

When working with external crates, it is advisable to check the implementation of this trait and program around any possible [`Error`]s.

That way, it is clear that std doesn't produce any errors and also that the user should be aware that it is a possibility in third-party crates.

@kpreid
Copy link
Contributor

kpreid commented Aug 9, 2022

std doesn't produce any errors

It does: The internal implementation of std::fmt::Write for an Adapter that wraps a std::io::Write produces a fmt::Error when the underlying destination returns a std::io::Error (while saving that error internally and returning it after the formatting is cancelled).

This can be observed in user code by implementing a formatting trait which is then used with io::Write::write_fmt() on a destination that errors.

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Aug 12, 2022
…triplett

Adding more verbose documentation for `std::fmt::Write`

Attempts to address rust-lang#98861
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Aug 12, 2022
…triplett

Adding more verbose documentation for `std::fmt::Write`

Attempts to address rust-lang#98861
@alexs-sh
Copy link
Contributor

alexs-sh commented Dec 4, 2022

Hi everyone.
May I kindly ask somebody to take a look into PR: #105172

This is a continuation of work on docs. And this is my first PR here. I will be grateful for any comments

alexs-sh added a commit to alexs-sh/rust that referenced this issue Jan 3, 2023
JohnTitor pushed a commit to JohnTitor/rust that referenced this issue Jan 14, 2023
…cottmcm

Added error documentation for write_fmt

This continuation of work at rust-lang#98861
@mwithington
Copy link

Is this still issue still open?

@chenyukang
Copy link
Member

I think we may close it since #105172 was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests