diff options
| author | bors <bors@rust-lang.org> | 2024-02-29 00:53:39 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-02-29 00:53:39 +0000 | 
| commit | d3d145ea1cae47ad392173f890577788117da3d9 (patch) | |
| tree | 5e57dc9f22594182dc617cb12e80515903ee8519 /library/std/src/io/stdio.rs | |
| parent | c475e2303b551d726307c646181e0677af1e0069 (diff) | |
| parent | 9f9daed889fec22f3e681b297f9eb50c488fdbcd (diff) | |
| download | rust-d3d145ea1cae47ad392173f890577788117da3d9.tar.gz rust-d3d145ea1cae47ad392173f890577788117da3d9.zip | |
Auto merge of #121770 - matthiaskrgr:rollup-wdher8r, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #110543 (Make `ReentrantLock` public) - #121689 ([rustdoc] Prevent inclusion of whitespace character after macro_rules ident) - #121724 (Use `LitKind::Err` for malformed floats) - #121735 (pattern analysis: Don't panic when encountering unexpected constructor) - #121743 (Opportunistically resolve regions when processing region outlives obligations) Failed merges: - #121326 (Detect empty leading where clauses on type aliases) - #121416 (Improve error messages for generics with default parameters) - #121669 (Count stashed errors again) - #121723 (Two diagnostic things) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/io/stdio.rs')
| -rw-r--r-- | library/std/src/io/stdio.rs | 45 | 
1 files changed, 35 insertions, 10 deletions
| diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 261b570dee7..455de6d98ba 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -11,8 +11,9 @@ use crate::fs::File; use crate::io::{ self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines, SpecReadByte, }; +use crate::panic::{RefUnwindSafe, UnwindSafe}; use crate::sync::atomic::{AtomicBool, Ordering}; -use crate::sync::{Arc, Mutex, MutexGuard, OnceLock, ReentrantMutex, ReentrantMutexGuard}; +use crate::sync::{Arc, Mutex, MutexGuard, OnceLock, ReentrantLock, ReentrantLockGuard}; use crate::sys::stdio; type LocalStream = Arc<Mutex<Vec<u8>>>; @@ -545,7 +546,7 @@ pub struct Stdout { // FIXME: this should be LineWriter or BufWriter depending on the state of // stdout (tty or not). Note that if this is not line buffered it // should also flush-on-panic or some form of flush-on-abort. - inner: &'static ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>, + inner: &'static ReentrantLock<RefCell<LineWriter<StdoutRaw>>>, } /// A locked reference to the [`Stdout`] handle. @@ -567,10 +568,10 @@ pub struct Stdout { #[must_use = "if unused stdout will immediately unlock"] #[stable(feature = "rust1", since = "1.0.0")] pub struct StdoutLock<'a> { - inner: ReentrantMutexGuard<'a, RefCell<LineWriter<StdoutRaw>>>, + inner: ReentrantLockGuard<'a, RefCell<LineWriter<StdoutRaw>>>, } -static STDOUT: OnceLock<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = OnceLock::new(); +static STDOUT: OnceLock<ReentrantLock<RefCell<LineWriter<StdoutRaw>>>> = OnceLock::new(); /// Constructs a new handle to the standard output of the current process. /// @@ -624,7 +625,7 @@ static STDOUT: OnceLock<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = OnceLo pub fn stdout() -> Stdout { Stdout { inner: STDOUT - .get_or_init(|| ReentrantMutex::new(RefCell::new(LineWriter::new(stdout_raw())))), + .get_or_init(|| ReentrantLock::new(RefCell::new(LineWriter::new(stdout_raw())))), } } @@ -635,7 +636,7 @@ pub fn cleanup() { let mut initialized = false; let stdout = STDOUT.get_or_init(|| { initialized = true; - ReentrantMutex::new(RefCell::new(LineWriter::with_capacity(0, stdout_raw()))) + ReentrantLock::new(RefCell::new(LineWriter::with_capacity(0, stdout_raw()))) }); if !initialized { @@ -678,6 +679,12 @@ impl Stdout { } } +#[stable(feature = "catch_unwind", since = "1.9.0")] +impl UnwindSafe for Stdout {} + +#[stable(feature = "catch_unwind", since = "1.9.0")] +impl RefUnwindSafe for Stdout {} + #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Stdout { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -737,6 +744,12 @@ impl Write for &Stdout { } } +#[stable(feature = "catch_unwind", since = "1.9.0")] +impl UnwindSafe for StdoutLock<'_> {} + +#[stable(feature = "catch_unwind", since = "1.9.0")] +impl RefUnwindSafe for StdoutLock<'_> {} + #[stable(feature = "rust1", since = "1.0.0")] impl Write for StdoutLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { @@ -786,7 +799,7 @@ impl fmt::Debug for StdoutLock<'_> { /// standard library or via raw Windows API calls, will fail. #[stable(feature = "rust1", since = "1.0.0")] pub struct Stderr { - inner: &'static ReentrantMutex<RefCell<StderrRaw>>, + inner: &'static ReentrantLock<RefCell<StderrRaw>>, } /// A locked reference to the [`Stderr`] handle. @@ -808,7 +821,7 @@ pub struct Stderr { #[must_use = "if unused stderr will immediately unlock"] #[stable(feature = "rust1", since = "1.0.0")] pub struct StderrLock<'a> { - inner: ReentrantMutexGuard<'a, RefCell<StderrRaw>>, + inner: ReentrantLockGuard<'a, RefCell<StderrRaw>>, } /// Constructs a new handle to the standard error of the current process. @@ -862,8 +875,8 @@ pub fn stderr() -> Stderr { // Note that unlike `stdout()` we don't use `at_exit` here to register a // destructor. Stderr is not buffered, so there's no need to run a // destructor for flushing the buffer - static INSTANCE: ReentrantMutex<RefCell<StderrRaw>> = - ReentrantMutex::new(RefCell::new(stderr_raw())); + static INSTANCE: ReentrantLock<RefCell<StderrRaw>> = + ReentrantLock::new(RefCell::new(stderr_raw())); Stderr { inner: &INSTANCE } } @@ -898,6 +911,12 @@ impl Stderr { } } +#[stable(feature = "catch_unwind", since = "1.9.0")] +impl UnwindSafe for Stderr {} + +#[stable(feature = "catch_unwind", since = "1.9.0")] +impl RefUnwindSafe for Stderr {} + #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Stderr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -957,6 +976,12 @@ impl Write for &Stderr { } } +#[stable(feature = "catch_unwind", since = "1.9.0")] +impl UnwindSafe for StderrLock<'_> {} + +#[stable(feature = "catch_unwind", since = "1.9.0")] +impl RefUnwindSafe for StderrLock<'_> {} + #[stable(feature = "rust1", since = "1.0.0")] impl Write for StderrLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { | 
