rust icon indicating copy to clipboard operation
rust copied to clipboard

Add `read_buf` equivalents for positioned reads

Open niklasf opened this issue 7 months ago • 20 comments

Adds the following items under the ~~read_buf (rust-lang/rust#78485)~~ read_buf_at (rust-lang/rust#140771) feature:

  • std::os::unix::fs::FileExt::read_buf_at
  • std::os::unix::fs::FileExt::read_buf_exact_at
  • std::os::windows::fs::FileExt::seek_read_buf

try-job: x86_64-msvc* try-job: test-various* try-job: dist-various*

niklasf avatar Apr 29 '25 13:04 niklasf

r? @tgross35

rustbot has assigned @tgross35. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

rustbot avatar Apr 29 '25 13:04 rustbot

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    |
585 |     pub fn read_buf(&self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0599]: no method named `as_nut` found for struct `BorrowedCursor` in the current scope
   --> library/std/src/sys/pal/windows/handle.rs:141:42
    |
141 |             self.synchronous_read(cursor.as_nut().as_mut_ptr(), cursor.capacity(), Some(offset))
    |                                          ^^^^^^
    |
help: there is a method `as_mut` with a similar name
    |
141 -             self.synchronous_read(cursor.as_nut().as_mut_ptr(), cursor.capacity(), Some(offset))
141 +             self.synchronous_read(cursor.as_mut().as_mut_ptr(), cursor.capacity(), Some(offset))
    |

error[E0061]: this method takes 2 arguments but 1 argument was supplied
   --> library/std/src/sys/fs/windows.rs:590:21
    |
590 |         self.handle.read_buf_at(cursor)
    |                     ^^^^^^^^^^^-------- argument #2 of type `u64` is missing
    |
note: method defined here
   --> library/std/src/sys/pal/windows/handle.rs:139:12
    |
139 |     pub fn read_buf_at(&self, mut cursor: BorrowedCursor<'_>, offset: u64) -> io::Result<()> {
    |            ^^^^^^^^^^^                                        -----------
help: provide the argument
    |
590 |         self.handle.read_buf_at(cursor, /* u64 */)
    |                                       +++++++++++

Some errors have detailed explanations: E0061, E0599.
For more information about an error, try `rustc --explain E0061`.
[RUSTC-TIMING] std test:false 2.650

rust-log-analyzer avatar Apr 29 '25 14:04 rust-log-analyzer

Have these changes been discussed with libs-api at all? Usually changes to unstable API need to be proposed at https://github.com/rust-lang/libs-team/ with the ACP issue template.

This needs some tests as well.

tgross35 avatar May 01 '25 00:05 tgross35

For the above, @rustbot author

tgross35 avatar May 01 '25 01:05 tgross35

Reminder, once the PR becomes ready for a review, use @rustbot ready.

rustbot avatar May 01 '25 01:05 rustbot

For consistency and clarity, could we include safety comments on each unsafe block? Even brief notes are helpful to understand the assumptions being made

Kivooeo avatar May 08 '25 04:05 Kivooeo

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

rust-log-analyzer avatar May 12 '25 21:05 rust-log-analyzer

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

rust-log-analyzer avatar May 12 '25 22:05 rust-log-analyzer

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

rust-log-analyzer avatar May 12 '25 22:05 rust-log-analyzer

Thank you both.

  • Opened an APC that was accepted, but items to be added under a new feature instead of read_buf. Moved to read_buf_at with new tracking issue #140771.
  • Added safety comments also for FFI calls.
  • Added tests.

@rustbot ready

niklasf avatar May 12 '25 23:05 niklasf

@bors try

tgross35 avatar May 28 '25 22:05 tgross35

:hourglass: Trying commit 85e1da142056d8591d972f156f4a9ca16171c98b with merge f76928546c97438a758c27b2f9381b78f73fcbc0...

bors avatar May 28 '25 23:05 bors

The job x86_64-msvc-1 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Updating files:  98% (52406/53474)
Updating files:  99% (52940/53474)
Updating files: 100% (53474/53474)
Updating files: 100% (53474/53474), done.
branch 'try' set up to track 'origin/try'.
Switched to a new branch 'try'
##[endgroup]
[command]"C:\Program Files\Git\bin\git.exe" log -1 --format=%H
f76928546c97438a758c27b2f9381b78f73fcbc0
##[group]Run src/ci/scripts/setup-environment.sh
src/ci/scripts/setup-environment.sh
---
file:.git/config remote.origin.url=https://github.com/rust-lang/rust
file:.git/config remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
file:.git/config gc.auto=0
file:.git/config http.https://github.com/.extraheader=AUTHORIZATION: basic ***
file:.git/config branch.try.remote=origin
file:.git/config branch.try.merge=refs/heads/try
file:.git/config submodule.library/backtrace.active=true
file:.git/config submodule.library/backtrace.url=https://github.com/rust-lang/backtrace-rs.git
file:.git/config submodule.library/stdarch.active=true
file:.git/config submodule.library/stdarch.url=https://github.com/rust-lang/stdarch.git
file:.git/config submodule.src/doc/book.active=true
---
failures:

---- fs::tests::test_seek_read_buf stdout ----

thread 'fs::tests::test_seek_read_buf' panicked at library\std\src\fs\tests.rs:635:9:
assertion `left == right` failed
  left: 9
 right: 0


failures:
    fs::tests::test_seek_read_buf

test result: FAILED. 561 passed; 1 failed; 5 ignored; 0 measured; 0 filtered out; finished in 56.85s

error: test failed, to rerun pass `-p std --lib`
Build completed unsuccessfully in 1:47:18
make: *** [Makefile:113: ci-msvc-py] Error 1
  local time: Thu May 29 01:02:38 CUT 2025
  network time: Thu, 29 May 2025 01:02:38 GMT
##[error]Process completed with exit code 2.
Post job cleanup.
[command]"C:\Program Files\Git\bin\git.exe" version

rust-log-analyzer avatar May 29 '25 01:05 rust-log-analyzer

:broken_heart: Test failed - checks-actions

bors avatar May 29 '25 01:05 bors

:warning: Warning :warning:

  • There are issue links (such as #123) in the commit messages of the following commits. Please remove them as they will spam the issue with references to the commit.
    • 05dcef0608ae14d0de2d96112a7c6eec933be650

rustbot avatar May 29 '25 18:05 rustbot

Ready for the next round of review.

The failed test on Windows was an assertion that I had (blindly) added about the seek position after seek_read_buf() with an empty buffer. Turns out it's a noop, but neither the existing seek_read() nor the current underlying Windows API guarantees it (afaict), so I just removed the assertion.

@rustbot ready

niklasf avatar May 29 '25 18:05 niklasf

Running another try, including a few other unix platforms

@bors2 try

tgross35 avatar Jun 10 '25 04:06 tgross35

:hourglass: Trying commit e8a35d4acf34ca1c93b9538a95034ed001f3682b with merge 2e522c2e8590b7b074d7a35dea51085165d83c67…

To cancel the try build, run the command @bors2 try cancel.

rust-bors[bot] avatar Jun 10 '25 04:06 rust-bors[bot]

@rustbot author

tgross35 avatar Jun 10 '25 05:06 tgross35

:sunny: Try build successful (CI) Build commit: 2e522c2e8590b7b074d7a35dea51085165d83c67 (2e522c2e8590b7b074d7a35dea51085165d83c67)

rust-bors[bot] avatar Jun 10 '25 06:06 rust-bors[bot]

Hey @niklasf gentle ping: this only needs a few small changes if you're able to get it over the line

tgross35 avatar Aug 13 '25 01:08 tgross35

:umbrella: The latest upstream changes (presumably #145334) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Aug 13 '25 11:08 bors

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

rustbot avatar Aug 18 '25 19:08 rustbot

Back after a while, rebased to resolve conflicts, and ready for the next round of review.

@rustbot ready

niklasf avatar Aug 18 '25 20:08 niklasf

The job pr-check-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
     |        -------- the method is available for `&Handle` here
     |
    ::: library/std/src/sys/pal/windows/handle.rs:20:1
     |
  20 | pub struct Handle(OwnedHandle);
     | ----------------- method `read_buf` not found for this struct
     |
     = help: items from traits can only be used if the trait is implemented and in scope
note: `io::Read` defines an item `read_buf`, perhaps you need to implement it
    --> library/std/src/io/mod.rs:732:1
     |
---
     |        -------- the method is available for `&Handle` here
     |
    ::: library/std/src/sys/pal/windows/handle.rs:20:1
     |
  20 | pub struct Handle(OwnedHandle);
     | ----------------- method `read_buf` not found for this struct
     |
     = help: items from traits can only be used if the trait is implemented and in scope
note: `io::Read` defines an item `read_buf`, perhaps you need to implement it
    --> library/std/src/io/mod.rs:732:1
     |
---

error[E0599]: no method named `read_buf` found for struct `Handle` in the current scope
    --> library/std/src/sys/pal/windows/handle.rs:347:18
     |
  20 | pub struct Handle(OwnedHandle);
     | ----------------- method `read_buf` not found for this struct
...
 347 |         (**self).read_buf(buf)
     |                  ^^^^^^^^
     |
    ::: library/std/src/io/mod.rs:1057:8
     |
1057 |     fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<()> {

rust-log-analyzer avatar Aug 18 '25 20:08 rust-log-analyzer

@rustbot ready

niklasf avatar Sep 03 '25 18:09 niklasf

Going to rerun the try job just in case, but LGTM. Thanks for the updates

@bors2 try

tgross35 avatar Sep 03 '25 18:09 tgross35

:hourglass: Trying commit c914c471b9d83f9e6c74b0e6c2c8044efd3a57dd with merge f0baf1cd9fa552c3e2ab50b1610b11ce86350ef2…

To cancel the try build, run the command @bors try cancel.

rust-bors[bot] avatar Sep 03 '25 18:09 rust-bors[bot]

:sunny: Try build successful (CI) Build commit: f0baf1cd9fa552c3e2ab50b1610b11ce86350ef2 (f0baf1cd9fa552c3e2ab50b1610b11ce86350ef2, parent: fd75a9c32d643f39c8c61df770d2cff60b3fefd5)

rust-bors[bot] avatar Sep 03 '25 21:09 rust-bors[bot]

@bors r+

tgross35 avatar Sep 03 '25 21:09 tgross35