| Age | Commit message (Collapse) | Author | Lines |
|
Closes #60271.
|
|
Make BufWriter use get_mut instead of manipulating inner in Write implementation
`get_mut` allows us to abstract over the implementation detail of inner being optional.
|
|
get_mut allows us to abstract over the implementation detail of inner being
optional.
|
|
This commit implements the `{read,write}_vectored` methods on more types
in the standard library, namely:
* `std::fs::File`
* `std::process::ChildStd{in,out,err}`
* `std::io::Std{in,out,err}`
* `std::io::Std{in,out,err}Lock`
* `std::io::Std{in,out,err}Raw`
Where supported the OS implementations hook up to native support,
otherwise it falls back to the already-defaulted implementation.
|
|
|
|
Calling `Read::read` or `Write::write` without checking the returned
`usize` value is almost always an error. Example code in the
documentation should demonstrate how to use the return value correctly.
Otherwise, people might copy the example code thinking that it is okay
to "fire and forget" these methods.
|
|
|
|
Fix link capitalization in documentation of std::io::BufWriter.
|
|
|
|
Resolves #55546
|
|
|
|
Add provided methods `Seek::{stream_len, stream_position}`
This adds two new, provided methods to the `io::Seek` trait:
- `fn stream_len(&mut self) -> Result<u64>`
- `fn stream_position(&mut self) -> Result<u64>`
Both are added for convenience and to improve readability in user code. Reading `file.stream_len()` is much better than to manually seek two or three times. Similarly, `file.stream_position()` is much more clear than `file.seek(SeekFrom::Current(0))`.
You can find prior discussions [in this internals thread](https://internals.rust-lang.org/t/pre-rfc-idea-extend-io-seek-with-convenience-methods-with-e-g-stream-len/9262). I think I addressed all concerns in that thread.
I already wrote three RFCs to add a small new API to libstd but I noticed that many public changes to libstd happen without an RFC. So I figured I can try opening a PR directly without going through RFCs first. After all, we do have rfcbot here too. If you think this change is too big to merge without an RFC, I can still close this PR and write an RFC.
|
|
Add new test case for possible bug in BufReader
When reading a large chunk from a BufReader, if all the bytes from the buffer have been already consumed, the internal buffer is bypassed entirely. However, it is not invalidated, and it's possible to access its contents using the `seek_relative` method, because it tries to reuse the existing buffer.
|
|
Fix typos in the documentation
Co-Authored-By: LukasKalbertodt <lukas.kalbertodt@gmail.com>
|
|
Fix SGX implementations of read/write_vectored.
|
|
|
|
|
|
|
|
These two methods are defined in terms of `Seek::seek` and are
added for convenience. Tests are included.
|
|
overhaul unused doc comments lint
This PR contains a number of improvements to the `unused_doc_comments` lint.
- Extends the span to cover the entire comment when using sugared doc comments.
- Triggers the lint for all unused doc comments on a node, instead of just the first one.
- Triggers the lint on macro expansions, and provides a help note explaining that doc comments must be expanded by the macro.
- Adds a label pointing at the node that cannot be documented.
Furthermore, this PR fixes any instances in rustc where a macro expansion was erroneously documented.
|
|
Report the diagnostic on macro expansions, and add a label indicating
why the comment is unused.
|
|
|
|
|
|
There are two moments when a BufRead object needs to empty it's internal
buffer:
- In a seek call;
- In a read call when all data in the internal buffer had been already
consumed and the output buffer has a greater or equal size than the
internal buffer.
In both cases, the buffer was not being properly emptied, but only
marked as consumed (self.pos = self.cap). That should be no problem if
the inner reader is only Read, but if it is Seek as well, then it's
possible to access the data in the buffer by using the seek_relative
method. In order to prevent this from happening, both self.pos and
self.cap should be set to 0.
Two test cases were added to detect that failure:
- test_buffered_reader_invalidated_after_read
- test_buffered_reader_invalidated_after_seek
Both tests are very similar to each other. The inner reader contains the
following data: [5, 6, 7, 0, 1, 2, 3, 4]. The buffer capacity is 3
bytes.
- First, we call fill_buffer, which loads [5, 6, 7] into the internal
buffer, and then consume those 3 bytes.
- Then we either read the 5 remaining bytes in a single read call or we
move to the end of the stream by calling seek. In both cases the
buffer should be emptied to prevent the previous data [5, 6, 7] from
being read.
- We now call seek_relative(-2) and read two bytes, which should give us
the last 2 bytes of the stream: [3, 4].
Before this commit, the the seek_relative method would consider that
we're still in the range of the internal buffer, so instead of fetching
data from the inner reader, it would return the two last bytes that were
incorrectly still in the buffer: [6, 7]. Therefore, the test would fail.
Now, when seek_relative is called the buffer is empty. So the expected
data [3, 4] is fetched from the inner reader and the test passes.
|
|
|
|
Relax Read bounds on a bunch of BufReader<R> methods
|
|
|
|
|
|
Fix copy-pasted typo for read_string return value
|
|
Add vectored read and write support
This functionality has lived for a while in the tokio ecosystem, where
it can improve performance by minimizing copies.
r? @alexcrichton
|
|
|
|
Use more impl header lifetime elision
Inspired by seeing explicit lifetimes on these two:
- https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html#impl-FusedIterator
- https://doc.rust-lang.org/nightly/std/primitive.u32.html#impl-Not
And a follow-up to https://github.com/rust-lang/rust/pull/54687, that started using IHLE in libcore.
Most of the changes in here fall into two big categories:
- Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop`, `Debug`, and `Clone`)
- Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`)
I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations [where the flipped one cannot elide the lifetime](https://internals.rust-lang.org/t/impl-type-parameter-aliases/9403/2?u=scottmcm).
I also removed two lifetimes that turned out to be completely unused; see https://github.com/rust-lang/rust/issues/41960#issuecomment-464557423
|
|
There are two big categories of changes in here
- Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop` & `Debug`)
- Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`)
I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations where the flipped one cannot elide the lifetime.
|
|
|
|
Returning &'a mut [u8] was unsound, and we may as well just have them
directly deref to their slices to make it easier to work with them.
|
|
This functionality has lived for a while in the tokio ecosystem, where
it can improve performance by minimizing copies.
|
|
|
|
|
|
|
|
cc #23344
|
|
JosephTLyons:Fix-question-mark-operator-in-stdio-document, r=wesleywiser
Fixed the link to the ? operator
I'm working on updating all broken links, but figured I'd break up the pull requests so they are easier to review, versus just one big pull request.
|
|
|
|
|
|
|
|
r=QuietMisdreavus
deny intra-doc link resolution failures in libstd
Fixes #56693.
Until we land a fix for the underlying issue (#56922), we can at least fix the failures in libstd so they don't propagate to downstream crates.
|
|
Defactored Bytes::read
Removed unneeded refactoring of read_one_byte, which removed the unneeded dynamic dispatch (`dyn Read`) used by that function.
This function is only used in one place in the entire Rust codebase; there doesn't seem to be a reason for it to exist (and there especially doesn't seem to be a reason for it to use dynamic dispatch)
|
|
|
|
|
|
Remove some unnecessary feature gates
fixes #56585
cc @jethrogb
|
|
* Update bootstrap compiler
* Update version to 1.33.0
* Remove some `#[cfg(stage0)]` annotations
Actually updating the version number is blocked on updating Cargo
|