Skip to content
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

Converted all platform-specific stdin/stdout/stderr implementations to use io:: traits #73495

Merged
merged 3 commits into from
Jun 23, 2020

Conversation

Lucretiel
Copy link
Contributor

@Lucretiel Lucretiel commented Jun 19, 2020

Currently, some of the platform-specific standard streams (src/libstd/sys/*/stdio.rs) manually implement parts of the io::Write interface directly as methods on the struct, rather than by actually implementing the trait. There doesn't seem to be any reason for this, other than an unused advantage of fn write(&self, ...) instead of fn write(&mut self, ...).

Unfortunately, this means that those implementations don't have the default-implemented io methods, like read_exact and write_all. This caused #72705, which adds forwarding methods to the user-facing standard stream implementations, to fail to compile on those platforms.

This change converts all such standard stream structs to use the standard library traits. This change should not cause any breakages, because the changed types are not publicly exported, and in fact are only ever used in src/libstd/io/stdio.rs.

@rust-highfive
Copy link
Collaborator

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 19, 2020
@dtolnay dtolnay added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jun 19, 2020
@hellow554
Copy link
Contributor

There are some modifications from &self to &mut self. Hopefully this won't break anything. You sure, that they aren't exported? If yes, then this LGTM.

@Lucretiel
Copy link
Contributor Author

Lucretiel commented Jun 19, 2020

You sure, that they aren't exported?

I'm at 99.9% sure. Here are the checks I did:

  • I know for sure that the std::sys isn't exported, and aside from the module declaration, that file makes no further reference to it. So they're definitely not publicly exported. The only issue is potential uses inside of libstd
  • I know for sure that the platform specific code doesn't make any further interior references to these types (that is, for example, no other file matching /src/libstd/sys/hermit/**.rs refers to the stream types in /src/libstd/sys/hermit/stdio.rs
  • I know for sure that the only meaningful references to the Stdin, Stdout, Stderr symbols are in either libstd/sys/*/stdio.rs or libstd/io/stdio.rs, and I've been combing through those files thoroughly recently as part of this PR, Added io forwarding methods to the stdio structs #72705, and Substantial refactor to the design of LineWriter #72808. This means that there shouldn't be any internal breakages.
  • I know that many of the sys::stdio types do use an io trait implementation, and all of the cases I know of these types being used are seamless conditional import (that is, either you use sys::unix::stdio or sys::hermit::stdio, with the idea being that the types in those modules should export identical interfaces. This means that the only way there could be an internal breakage is if someone uses specifically one of these types (like, they specifically use hermit::stdio instead of *::stdio) and specifically depend on being able to call write on &self instead of &mut self.

@sfackler
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 19, 2020

📌 Commit 0094f44 has been approved by sfackler

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 19, 2020
Manishearth added a commit to Manishearth/rust that referenced this pull request Jun 20, 2020
Converted all platform-specific stdin/stdout/stderr implementations to use io:: traits

Currently, some of the platform-specific standard streams (`src/libstd/sys/*/stdio.rs`) manually implement parts of the `io::Write` interface directly as methods on the struct, rather than by actually implementing the trait. There doesn't seem to be any reason for this, other than an unused advantage of `fn write(&self, ...)` instead of `fn write(&mut self, ...)`.

Unfortunately, this means that those implementations don't have the default-implemented io methods, like `read_exact` and `write_all`. This caused rust-lang#72705, which adds forwarding methods to the user-facing standard stream implementations, to fail to compile on those platforms.

This change converts *all* such standard stream structs to use the standard library traits. This change should not cause any breakages, because the changed types are not publicly exported, and in fact are only ever used in `src/libstd/io/stdio.rs`.
Manishearth added a commit to Manishearth/rust that referenced this pull request Jun 20, 2020
Converted all platform-specific stdin/stdout/stderr implementations to use io:: traits

Currently, some of the platform-specific standard streams (`src/libstd/sys/*/stdio.rs`) manually implement parts of the `io::Write` interface directly as methods on the struct, rather than by actually implementing the trait. There doesn't seem to be any reason for this, other than an unused advantage of `fn write(&self, ...)` instead of `fn write(&mut self, ...)`.

Unfortunately, this means that those implementations don't have the default-implemented io methods, like `read_exact` and `write_all`. This caused rust-lang#72705, which adds forwarding methods to the user-facing standard stream implementations, to fail to compile on those platforms.

This change converts *all* such standard stream structs to use the standard library traits. This change should not cause any breakages, because the changed types are not publicly exported, and in fact are only ever used in `src/libstd/io/stdio.rs`.
Manishearth added a commit to Manishearth/rust that referenced this pull request Jun 21, 2020
Converted all platform-specific stdin/stdout/stderr implementations to use io:: traits

Currently, some of the platform-specific standard streams (`src/libstd/sys/*/stdio.rs`) manually implement parts of the `io::Write` interface directly as methods on the struct, rather than by actually implementing the trait. There doesn't seem to be any reason for this, other than an unused advantage of `fn write(&self, ...)` instead of `fn write(&mut self, ...)`.

Unfortunately, this means that those implementations don't have the default-implemented io methods, like `read_exact` and `write_all`. This caused rust-lang#72705, which adds forwarding methods to the user-facing standard stream implementations, to fail to compile on those platforms.

This change converts *all* such standard stream structs to use the standard library traits. This change should not cause any breakages, because the changed types are not publicly exported, and in fact are only ever used in `src/libstd/io/stdio.rs`.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 23, 2020
Rollup of 7 pull requests

Successful merges:

 - rust-lang#71756 (add Windows system error codes that should map to io::ErrorKind::TimedOut)
 - rust-lang#73495 (Converted all platform-specific stdin/stdout/stderr implementations to use io:: traits)
 - rust-lang#73575 (Fix typo in error_codes doc)
 - rust-lang#73578 (Make is_freeze and is_copy_modulo_regions take TyCtxtAt)
 - rust-lang#73586 (switch_ty is redundant)
 - rust-lang#73600 (Fix spurious 'value moved here in previous iteration of loop' messages)
 - rust-lang#73610 (Clean up E0699 explanation)

Failed merges:

r? @ghost
@bors bors merged commit 5426586 into rust-lang:master Jun 23, 2020
@cuviper cuviper added this to the 1.46 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants