Skip to content

Commit c58ceb7

Browse files
committed
stdio_locked: updates based on feedback
Rename methods to `into_locked`. Remove type aliases for owned locks.
1 parent b3db5cd commit c58ceb7

File tree

3 files changed

+14
-74
lines changed

3 files changed

+14
-74
lines changed

library/std/src/io/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,6 @@ pub use self::stdio::{stderr, stdin, stdout, Stderr, Stdin, Stdout};
281281
pub use self::stdio::{stderr_locked, stdin_locked, stdout_locked};
282282
#[stable(feature = "rust1", since = "1.0.0")]
283283
pub use self::stdio::{StderrLock, StdinLock, StdoutLock};
284-
#[unstable(feature = "stdio_locked", issue = "none")]
285-
pub use self::stdio::{StderrOwnedLock, StdinOwnedLock, StdoutOwnedLock};
286284
#[unstable(feature = "print_internals", issue = "none")]
287285
pub use self::stdio::{_eprint, _print};
288286
#[stable(feature = "rust1", since = "1.0.0")]

library/std/src/io/stdio.rs

+11-54
Original file line numberDiff line numberDiff line change
@@ -261,21 +261,6 @@ pub struct StdinLock<'a> {
261261
inner: MutexGuard<'a, BufReader<StdinRaw>>,
262262
}
263263

264-
/// Owned locked [`Stdin`] handle, returned by [`Stdin::into_lock`] and
265-
/// [`io::stdin_locked`].
266-
///
267-
/// This is exactly like [`StdinLock`], except that it can outlive the
268-
/// [`Stdin`] handle that was used to create it. See the [`StdinLock`]
269-
/// documentation for more details.
270-
///
271-
/// ### Note: Windows Portability Consideration
272-
///
273-
/// When operating in a console, the Windows implementation of this stream does not support
274-
/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return
275-
/// an error.
276-
#[unstable(feature = "stdio_locked", issue = "none")]
277-
pub type StdinOwnedLock = StdinLock<'static>;
278-
279264
/// Constructs a new handle to the standard input of the current process.
280265
///
281266
/// Each handle returned is a reference to a shared global buffer whose access
@@ -363,8 +348,8 @@ pub fn stdin() -> Stdin {
363348
/// }
364349
/// ```
365350
#[unstable(feature = "stdio_locked", issue = "none")]
366-
pub fn stdin_locked() -> StdinOwnedLock {
367-
stdin().into_lock()
351+
pub fn stdin_locked() -> StdinLock<'static> {
352+
stdin().into_locked()
368353
}
369354

370355
impl Stdin {
@@ -451,14 +436,14 @@ impl Stdin {
451436
///
452437
/// fn main() -> io::Result<()> {
453438
/// let mut buffer = String::new();
454-
/// let mut handle = io::stdin().into_lock();
439+
/// let mut handle = io::stdin().into_locked();
455440
///
456441
/// handle.read_to_string(&mut buffer)?;
457442
/// Ok(())
458443
/// }
459444
/// ```
460445
#[unstable(feature = "stdio_locked", issue = "none")]
461-
pub fn into_lock(self) -> StdinOwnedLock {
446+
pub fn into_locked(self) -> StdinLock<'static> {
462447
self.lock_any()
463448
}
464449
}
@@ -601,20 +586,6 @@ pub struct StdoutLock<'a> {
601586
inner: ReentrantMutexGuard<'a, RefCell<LineWriter<StdoutRaw>>>,
602587
}
603588

604-
/// Owned locked [`Stdout`] handle, returned by [`Stdout::into_lock`] and
605-
/// [`io::stdout_locked`].
606-
///
607-
/// This is exactly like [`StdoutLock`], except that it can outlive the
608-
/// [`Stdout`] handle that was used to create it. See the [`StdoutLock`]
609-
/// documentation for more details.
610-
///
611-
/// ### Note: Windows Portability Consideration
612-
/// When operating in a console, the Windows implementation of this stream does not support
613-
/// non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return
614-
/// an error.
615-
#[unstable(feature = "stdio_locked", issue = "none")]
616-
pub type StdoutOwnedLock = StdoutLock<'static>;
617-
618589
static STDOUT: SyncOnceCell<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = SyncOnceCell::new();
619590

620591
/// Constructs a new handle to the standard output of the current process.
@@ -699,7 +670,7 @@ pub fn stdout() -> Stdout {
699670
/// ```
700671
#[unstable(feature = "stdio_locked", issue = "none")]
701672
pub fn stdout_locked() -> StdoutLock<'static> {
702-
stdout().into_lock()
673+
stdout().into_locked()
703674
}
704675

705676
pub fn cleanup() {
@@ -767,15 +738,15 @@ impl Stdout {
767738
/// use std::io::{self, Write};
768739
///
769740
/// fn main() -> io::Result<()> {
770-
/// let mut handle = io::stdout().into_lock();
741+
/// let mut handle = io::stdout().into_locked();
771742
///
772743
/// handle.write_all(b"hello world")?;
773744
///
774745
/// Ok(())
775746
/// }
776747
/// ```
777748
#[unstable(feature = "stdio_locked", issue = "none")]
778-
pub fn into_lock(self) -> StdoutOwnedLock {
749+
pub fn into_locked(self) -> StdoutLock<'static> {
779750
self.lock_any()
780751
}
781752
}
@@ -898,20 +869,6 @@ pub struct StderrLock<'a> {
898869
inner: ReentrantMutexGuard<'a, RefCell<StderrRaw>>,
899870
}
900871

901-
/// Owned locked [`Stderr`] handle, returned by [`Stderr::into_lock`] and
902-
/// [`io::stderr_locked`].
903-
///
904-
/// This is exactly like [`StderrLock`], except that it can outlive the the
905-
/// [`Stderr`] handle that was used to create it. See the [`StderrLock`]
906-
/// documentation for more details.
907-
///
908-
/// ### Note: Windows Portability Consideration
909-
/// When operating in a console, the Windows implementation of this stream does not support
910-
/// non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return
911-
/// an error.
912-
#[unstable(feature = "stdio_locked", issue = "none")]
913-
pub type StderrOwnedLock = StderrLock<'static>;
914-
915872
/// Constructs a new handle to the standard error of the current process.
916873
///
917874
/// This handle is not buffered.
@@ -989,8 +946,8 @@ pub fn stderr() -> Stderr {
989946
/// }
990947
/// ```
991948
#[unstable(feature = "stdio_locked", issue = "none")]
992-
pub fn stderr_locked() -> StderrOwnedLock {
993-
stderr().into_lock()
949+
pub fn stderr_locked() -> StderrLock<'static> {
950+
stderr().into_locked()
994951
}
995952

996953
impl Stderr {
@@ -1041,15 +998,15 @@ impl Stderr {
1041998
///
1042999
/// fn foo() -> io::Result<()> {
10431000
/// let stderr = io::stderr();
1044-
/// let mut handle = stderr.into_lock();
1001+
/// let mut handle = stderr.into_locked();
10451002
///
10461003
/// handle.write_all(b"hello world")?;
10471004
///
10481005
/// Ok(())
10491006
/// }
10501007
/// ```
10511008
#[unstable(feature = "stdio_locked", issue = "none")]
1052-
pub fn into_lock(self) -> StderrOwnedLock {
1009+
pub fn into_locked(self) -> StderrLock<'static> {
10531010
self.lock_any()
10541011
}
10551012
}

library/std/src/io/stdio/tests.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,6 @@ fn panic_doesnt_poison() {
4747
let _a = _a.lock();
4848
}
4949

50-
#[test]
51-
fn stderr_owned_lock_static() {
52-
assert_static::<StderrOwnedLock>();
53-
}
54-
#[test]
55-
fn stdin_owned_lock_static() {
56-
assert_static::<StdinOwnedLock>();
57-
}
58-
#[test]
59-
fn stdout_owned_lock_static() {
60-
assert_static::<StdoutOwnedLock>();
61-
}
62-
63-
fn assert_static<T: 'static>() {}
64-
6550
#[test]
6651
#[cfg_attr(target_os = "emscripten", ignore)]
6752
fn test_lock_stderr() {
@@ -107,9 +92,9 @@ impl<'a> Stdio<'a> for Stdout {
10792

10893
// Helper trait to make lock testing function generic.
10994
trait StdioOwnedLock: 'static {}
110-
impl StdioOwnedLock for StderrOwnedLock {}
111-
impl StdioOwnedLock for StdinOwnedLock {}
112-
impl StdioOwnedLock for StdoutOwnedLock {}
95+
impl StdioOwnedLock for StderrLock<'static> {}
96+
impl StdioOwnedLock for StdinLock<'static> {}
97+
impl StdioOwnedLock for StdoutLock<'static> {}
11398

11499
// Tests locking on stdio handles by starting two threads and checking that
115100
// they block each other appropriately.

0 commit comments

Comments
 (0)