-
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
Read::read_exact docs unnecessarily scare off users #72186
Comments
I think I authored or at least reviewed the changes that made the Would it make sense to copy the longer explanatory paragraph to |
@rustbot claim |
I'm not sure I understand the confusion. This paragraph:
applies to implementations of
it just says to pass a regularly allocated |
I don't think the text was ever incorrect, it's just that someone skimming the docs can read things incorrectly. As I understand it, in the case I opened this issue for, the user certainly didn't read and understand the entire paragraph. They just saw "no guarantees", and decided this function wasn't the right thing to use. I'm OK with needing people to read the entire doc, but I think this goes beyond that? Particularly, if someone misreads or doesn't understand the word "implementations" in the first sentence of the paragraph, it reads as literally not guaranteeing anything about the output. I thought this was overly harsh for something the majority of users shouldn't have to care about, especially when it's harsher than another function, Plus, I think plenty of users who will encounter this before they understand proper terminology surrounding traits - "implementations" refers to someone implementing the trait, but that's not exactly obvious until someone's worked with rust for longer. And reading from a file is often a simple thing one might try to do before exploring more complicated aspects of the language? I guess I think it's totally understandable to misread this - even if they pay attention and try to understand the entire docs. Maybe something like renaming read, like suggested in https://internals.rust-lang.org/t/poor-naming-of-read-write-i-o-methods/12685/13, would be a better long-term solution for getting people to actually use I appreciate the changes in #74486, and I apologize for not being active on this issue. But I'd also argue that if this issue was ever valid, it still is - and this should be reopened. |
I know this thread has been closed for a while, but maybe I can offer my two cents as someone who misread the documentation and recently encountered the same confusion: The context switch from providing documentation to callers to providing documentation to implementers is only stated after the warning, after alarm bells had already gone off in my head, so in a sense, it's my mistake for getting distracted by those warnings and not reading more carefully, but on the other hand, I think reordering from
to
could provide a simple win. Going one step further to
would have been even more clear, but I could see how from a certain perspective this might seem unnecessarily wordy, or might not be consistent with other documentation. In hindsight, the documentation for |
io::Read trait: make it more clear when we are adressing implementations vs callers Inspired by [this](rust-lang#72186 (comment)) comment. For some reason we only have that `buf` warning in `read` and `read_exact`, even though it affects a bunch of other functions of this trait as well. It doesn't seem worth copy-pasting the same text everywhere though so I did not change this.
io::Read trait: make it more clear when we are adressing implementations vs callers Inspired by [this](rust-lang#72186 (comment)) comment. For some reason we only have that `buf` warning in `read` and `read_exact`, even though it affects a bunch of other functions of this trait as well. It doesn't seem worth copy-pasting the same text everywhere though so I did not change this.
Rollup merge of rust-lang#122276 - RalfJung:io-read, r=Nilstrieb io::Read trait: make it more clear when we are adressing implementations vs callers Inspired by [this](rust-lang#72186 (comment)) comment. For some reason we only have that `buf` warning in `read` and `read_exact`, even though it affects a bunch of other functions of this trait as well. It doesn't seem worth copy-pasting the same text everywhere though so I did not change this.
In a recent URLO post, someone saw the "no guarantees" paragraph in
read_exact
, and this convinced them not to use it (and to instead useread
).The post: (link)
The paragraph:
While the caution is (or at least was) legitimate, I think for today's rust it's a bit negative. And if this is a user's first real
read
method they use, then I can 100% understand getting thrown off by this language.I'd like to think we can reduce the caution necessary when using it, while still keeping the caution for implementors. Thoughts on replacing it with a more positive message, like the following?
The italicized "implementations" is taken from the documentation on
read
, which reads:I don't think it's necessary to modify the paragraph on
read
, as it has much more overall content, as it also contains this following paragraph:In addition, the
read
documentation is big enough that users can skip over the "no guarantees" paragraph. Case in point, the user from the URLO thread above chose to useread
, while avoidingread_exact
, even thoughread
contains the exact same paragraph.I'll end by saying I don't know the full history, but I think this might have had something to do with passing uninitialized byte buffers to read methods. I believe that it's been decided that passing in an uninitialized buffer is UB, though, so it shouldn't be as big of a concern. The current discussion of reading into uninitialized buffers is at 42788.
This issue has been assigned to @poliorcetics via this comment.
The text was updated successfully, but these errors were encountered: