-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Discrepancy between docs and implementation of BufReader::fill_buf #48022
Copy link
Copy link
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.P-mediumMedium priorityMedium priority
Description
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.P-mediumMedium priorityMedium priority
Type
Fields
Give feedbackNo fields configured for issues without a type.
Would you like to fix this bug? If so, here's how.
The documentation currently states that
BufRead::fill_buf:However, this is not what
BufReader's implementation of that method does. It will only fill the buffer if no data is currently buffered. If data is already present in the buffer, no filling takes place:I would argue that the current behavior of
BufReader's implementation is usually what users would want to do, but if does not match the documentation of, nor the name of,fill_buf. I don't know what the right solution here is, but I suspect the only safe thing to do would be to updateBufReader's implementation to match the docs (i.e., to make it actually fill its buffer), and then to add another method toBufRead(perhapsbuf_bytes?) that gives the currently buffered contents, regardless of the amount of buffered data, and without reading from the underlyingRead.