about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTaylor Yu <tlyu@mit.edu>2021-07-02 15:56:56 -0500
committerTaylor Yu <tlyu@mit.edu>2021-07-02 15:56:56 -0500
commitc58ceb7a42b5e06e2d7ba5fe727b05af5d073d3e (patch)
treea024176cead0f14a6b61e057595073d80aaab5dd
parentb3db5cd46c6941563ae8792cf61160c5793d397a (diff)
downloadrust-c58ceb7a42b5e06e2d7ba5fe727b05af5d073d3e.tar.gz
rust-c58ceb7a42b5e06e2d7ba5fe727b05af5d073d3e.zip
stdio_locked: updates based on feedback
Rename methods to `into_locked`. Remove type aliases for owned locks.
-rw-r--r--library/std/src/io/mod.rs2
-rw-r--r--library/std/src/io/stdio.rs65
-rw-r--r--library/std/src/io/stdio/tests.rs21
3 files changed, 14 insertions, 74 deletions
diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs
index 9e8996a3e56..acd4e0d7989 100644
--- a/library/std/src/io/mod.rs
+++ b/library/std/src/io/mod.rs
@@ -281,8 +281,6 @@ pub use self::stdio::{stderr, stdin, stdout, Stderr, Stdin, Stdout};
 pub use self::stdio::{stderr_locked, stdin_locked, stdout_locked};
 #[stable(feature = "rust1", since = "1.0.0")]
 pub use self::stdio::{StderrLock, StdinLock, StdoutLock};
-#[unstable(feature = "stdio_locked", issue = "none")]
-pub use self::stdio::{StderrOwnedLock, StdinOwnedLock, StdoutOwnedLock};
 #[unstable(feature = "print_internals", issue = "none")]
 pub use self::stdio::{_eprint, _print};
 #[stable(feature = "rust1", since = "1.0.0")]
diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs
index 026d2781263..293f0e31ce0 100644
--- a/library/std/src/io/stdio.rs
+++ b/library/std/src/io/stdio.rs
@@ -261,21 +261,6 @@ pub struct StdinLock<'a> {
     inner: MutexGuard<'a, BufReader<StdinRaw>>,
 }
 
-/// Owned locked [`Stdin`] handle, returned by [`Stdin::into_lock`] and
-/// [`io::stdin_locked`].
-///
-/// This is exactly like [`StdinLock`], except that it can outlive the
-/// [`Stdin`] handle that was used to create it. See the [`StdinLock`]
-/// documentation for more details.
-///
-/// ### Note: Windows Portability Consideration
-///
-/// When operating in a console, the Windows implementation of this stream does not support
-/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return
-/// an error.
-#[unstable(feature = "stdio_locked", issue = "none")]
-pub type StdinOwnedLock = StdinLock<'static>;
-
 /// Constructs a new handle to the standard input of the current process.
 ///
 /// Each handle returned is a reference to a shared global buffer whose access
@@ -363,8 +348,8 @@ pub fn stdin() -> Stdin {
 /// }
 /// ```
 #[unstable(feature = "stdio_locked", issue = "none")]
-pub fn stdin_locked() -> StdinOwnedLock {
-    stdin().into_lock()
+pub fn stdin_locked() -> StdinLock<'static> {
+    stdin().into_locked()
 }
 
 impl Stdin {
@@ -451,14 +436,14 @@ impl Stdin {
     ///
     /// fn main() -> io::Result<()> {
     ///     let mut buffer = String::new();
-    ///     let mut handle = io::stdin().into_lock();
+    ///     let mut handle = io::stdin().into_locked();
     ///
     ///     handle.read_to_string(&mut buffer)?;
     ///     Ok(())
     /// }
     /// ```
     #[unstable(feature = "stdio_locked", issue = "none")]
-    pub fn into_lock(self) -> StdinOwnedLock {
+    pub fn into_locked(self) -> StdinLock<'static> {
         self.lock_any()
     }
 }
@@ -601,20 +586,6 @@ pub struct StdoutLock<'a> {
     inner: ReentrantMutexGuard<'a, RefCell<LineWriter<StdoutRaw>>>,
 }
 
-/// Owned locked [`Stdout`] handle, returned by [`Stdout::into_lock`] and
-/// [`io::stdout_locked`].
-///
-/// This is exactly like [`StdoutLock`], except that it can outlive the
-/// [`Stdout`] handle that was used to create it. See the [`StdoutLock`]
-/// documentation for more details.
-///
-/// ### Note: Windows Portability Consideration
-/// When operating in a console, the Windows implementation of this stream does not support
-/// non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return
-/// an error.
-#[unstable(feature = "stdio_locked", issue = "none")]
-pub type StdoutOwnedLock = StdoutLock<'static>;
-
 static STDOUT: SyncOnceCell<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = SyncOnceCell::new();
 
 /// Constructs a new handle to the standard output of the current process.
@@ -699,7 +670,7 @@ pub fn stdout() -> Stdout {
 /// ```
 #[unstable(feature = "stdio_locked", issue = "none")]
 pub fn stdout_locked() -> StdoutLock<'static> {
-    stdout().into_lock()
+    stdout().into_locked()
 }
 
 pub fn cleanup() {
@@ -767,7 +738,7 @@ impl Stdout {
     /// use std::io::{self, Write};
     ///
     /// fn main() -> io::Result<()> {
-    ///     let mut handle = io::stdout().into_lock();
+    ///     let mut handle = io::stdout().into_locked();
     ///
     ///     handle.write_all(b"hello world")?;
     ///
@@ -775,7 +746,7 @@ impl Stdout {
     /// }
     /// ```
     #[unstable(feature = "stdio_locked", issue = "none")]
-    pub fn into_lock(self) -> StdoutOwnedLock {
+    pub fn into_locked(self) -> StdoutLock<'static> {
         self.lock_any()
     }
 }
@@ -898,20 +869,6 @@ pub struct StderrLock<'a> {
     inner: ReentrantMutexGuard<'a, RefCell<StderrRaw>>,
 }
 
-/// Owned locked [`Stderr`] handle, returned by [`Stderr::into_lock`] and
-/// [`io::stderr_locked`].
-///
-/// This is exactly like [`StderrLock`], except that it can outlive the the
-/// [`Stderr`] handle that was used to create it. See the [`StderrLock`]
-/// documentation for more details.
-///
-/// ### Note: Windows Portability Consideration
-/// When operating in a console, the Windows implementation of this stream does not support
-/// non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return
-/// an error.
-#[unstable(feature = "stdio_locked", issue = "none")]
-pub type StderrOwnedLock = StderrLock<'static>;
-
 /// Constructs a new handle to the standard error of the current process.
 ///
 /// This handle is not buffered.
@@ -989,8 +946,8 @@ pub fn stderr() -> Stderr {
 /// }
 /// ```
 #[unstable(feature = "stdio_locked", issue = "none")]
-pub fn stderr_locked() -> StderrOwnedLock {
-    stderr().into_lock()
+pub fn stderr_locked() -> StderrLock<'static> {
+    stderr().into_locked()
 }
 
 impl Stderr {
@@ -1041,7 +998,7 @@ impl Stderr {
     ///
     /// fn foo() -> io::Result<()> {
     ///     let stderr = io::stderr();
-    ///     let mut handle = stderr.into_lock();
+    ///     let mut handle = stderr.into_locked();
     ///
     ///     handle.write_all(b"hello world")?;
     ///
@@ -1049,7 +1006,7 @@ impl Stderr {
     /// }
     /// ```
     #[unstable(feature = "stdio_locked", issue = "none")]
-    pub fn into_lock(self) -> StderrOwnedLock {
+    pub fn into_locked(self) -> StderrLock<'static> {
         self.lock_any()
     }
 }
diff --git a/library/std/src/io/stdio/tests.rs b/library/std/src/io/stdio/tests.rs
index d84537e54de..b1df6b7131c 100644
--- a/library/std/src/io/stdio/tests.rs
+++ b/library/std/src/io/stdio/tests.rs
@@ -48,21 +48,6 @@ fn panic_doesnt_poison() {
 }
 
 #[test]
-fn stderr_owned_lock_static() {
-    assert_static::<StderrOwnedLock>();
-}
-#[test]
-fn stdin_owned_lock_static() {
-    assert_static::<StdinOwnedLock>();
-}
-#[test]
-fn stdout_owned_lock_static() {
-    assert_static::<StdoutOwnedLock>();
-}
-
-fn assert_static<T: 'static>() {}
-
-#[test]
 #[cfg_attr(target_os = "emscripten", ignore)]
 fn test_lock_stderr() {
     test_lock(stderr, stderr_locked);
@@ -107,9 +92,9 @@ impl<'a> Stdio<'a> for Stdout {
 
 // Helper trait to make lock testing function generic.
 trait StdioOwnedLock: 'static {}
-impl StdioOwnedLock for StderrOwnedLock {}
-impl StdioOwnedLock for StdinOwnedLock {}
-impl StdioOwnedLock for StdoutOwnedLock {}
+impl StdioOwnedLock for StderrLock<'static> {}
+impl StdioOwnedLock for StdinLock<'static> {}
+impl StdioOwnedLock for StdoutLock<'static> {}
 
 // Tests locking on stdio handles by starting two threads and checking that
 // they block each other appropriately.