-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Implement default methods for io::Empty
and io::Sink
#137051
Conversation
854723e
to
bb69541
Compare
As far as I know, we technically don't guarantee that the ping @rust-lang/libs-api - Please speak up if you don't think it's okay that |
bb69541
to
8250dbe
Compare
I've added nop @rustbot label -S-waiting-on-author +S-waiting-on-review |
This comment has been minimized.
This comment has been minimized.
Test write-fmt-error expects a panic for rust/tests/ui/write-fmt-errors.rs Lines 36 to 41 in ed49386
Should I change the test or revert the |
I don't think the purpose of that test is to test the behaviour of io::sink() specifically. It should be fine to change it to something that actually writes. (E.g. |
6e053fc
to
d846e72
Compare
I've added tests for the new impls. I also decided to keep In the standard library, only rust/library/std/src/io/mod.rs Lines 2729 to 2731 in f04bbc6
This could be somewhat improved by making it conditional on whether the first has finished (but then constant propagation is probably worsened): fn is_read_vectored(&self) -> bool {
if !self.done_first { self.first.is_read_vectored() } else { self.second.is_read_vectored() }
} In the standard library, only |
@m-ou-se Hey, friendly 2-week ping. Would you mind taking a look at the changes since your last review? |
d846e72
to
24978bd
Compare
Eliminate any redundant, unobservable logic from the their default method implementations. The observable changes are that `Write::write_fmt` for both types now ignores the formatting arguments, so a user fmt impl which has side effects is not invoked, and `Write::write_all_vectored` for both types does not advance the borrowed buffers. Neither behavior is guaranteed by the docs and the latter is documented as unspecified. `Empty` is not marked as vectored, so that `Chain<Empty, _>` and `Chain<_, Empty>` are not forced to be vectored.
24978bd
to
523b9d9
Compare
@bors r+ |
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#135394 (`MaybeUninit` inherent slice methods part 2) - rust-lang#137051 (Implement default methods for `io::Empty` and `io::Sink`) - rust-lang#138001 (mir_build: consider privacy when checking for irrefutable patterns) - rust-lang#138540 (core/slice: Mark some `split_off` variants unstably const) - rust-lang#138589 (If a label is placed on the block of a loop instead of the header, suggest moving it to the header.) - rust-lang#138594 (Fix next solver handling of shallow trait impl check) - rust-lang#138613 (Remove E0773 "A builtin-macro was defined more than once.") Failed merges: - rust-lang#138602 (Slim `rustc_parse_format` dependencies down) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#135394 (`MaybeUninit` inherent slice methods part 2) - rust-lang#137051 (Implement default methods for `io::Empty` and `io::Sink`) - rust-lang#138001 (mir_build: consider privacy when checking for irrefutable patterns) - rust-lang#138540 (core/slice: Mark some `split_off` variants unstably const) - rust-lang#138589 (If a label is placed on the block of a loop instead of the header, suggest moving it to the header.) - rust-lang#138594 (Fix next solver handling of shallow trait impl check) - rust-lang#138613 (Remove E0773 "A builtin-macro was defined more than once.") Failed merges: - rust-lang#138602 (Slim `rustc_parse_format` dependencies down) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#137051 - thaliaarchi:io-optional-impls/empty, r=m-ou-se Implement default methods for `io::Empty` and `io::Sink` Implements default methods of `io::Read`, `io::BufRead`, and `io::Write` for `io::Empty` and `io::Sink`. These implementations are equivalent to the defaults, except in doing less unnecessary work. `Read::read_to_string` and `BufRead::read_line` both have a redundant call to `str::from_utf8` which can't be inlined from `core` and `Write::write_all_vectored` has slicing logic which can't be simplified (See on [Compiler Explorer](https://rust.godbolt.org/z/KK6xcrWr4)). The rest are optimized to the minimal with `-C opt-level=3`, but this PR gives that benefit to unoptimized builds. This includes an implementation of `Write::write_fmt` which just ignores the `fmt::Arguments<'_>`. This could be problematic whenever a user formatting impl is impure, but the docs do not guarantee that the args will be expanded. Tracked in rust-lang#136756. r? `@m-ou-se`
Implements default methods of
io::Read
,io::BufRead
, andio::Write
forio::Empty
andio::Sink
. These implementations are equivalent to the defaults, except in doing less unnecessary work.Read::read_to_string
andBufRead::read_line
both have a redundant call tostr::from_utf8
which can't be inlined fromcore
andWrite::write_all_vectored
has slicing logic which can't be simplified (See on Compiler Explorer). The rest are optimized to the minimal with-C opt-level=3
, but this PR gives that benefit to unoptimized builds.This includes an implementation of
Write::write_fmt
which just ignores thefmt::Arguments<'_>
. This could be problematic whenever a user formatting impl is impure, but the docs do not guarantee that the args will be expanded.Tracked in #136756.
r? @m-ou-se