Skip to content

Commit

Permalink
Rollup merge of rust-lang#89693 - jkugelman:must-use-stdin-stdout-std…
Browse files Browse the repository at this point in the history
…err-locks, r=joshtriplett

Add #[must_use] to stdin/stdout/stderr locks

Affected methods:

```rust
std::io           fn stdin_locked() -> StdinLock<'static>;
std::io::Stdin    fn lock(&self) -> StdinLock<'_>;
std::io           fn stdout_locked() -> StdoutLock<'static>;
std::io::Stdout   fn lock(&self) -> StdoutLock<'_>;
std::io           fn stderr_locked() -> StderrLock<'static>;
std::io::Stderr   fn lock(&self) -> StderrLock<'_>;
```

Parent issue: rust-lang#89692
  • Loading branch information
matthiaskrgr committed Oct 9, 2021
2 parents 45ff2fb + e27bfb6 commit 90afb75
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions library/std/src/io/stdio.rs
Expand Up @@ -256,6 +256,7 @@ pub struct Stdin {
/// Ok(())
/// }
/// ```
#[must_use = "if unused stdin will immediately unlock"]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct StdinLock<'a> {
inner: MutexGuard<'a, BufReader<StdinRaw>>,
Expand Down Expand Up @@ -624,6 +625,7 @@ pub struct Stdout {
/// 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.
#[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>>>,
Expand Down Expand Up @@ -907,6 +909,7 @@ pub struct Stderr {
/// 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.
#[must_use = "if unused stderr will immediately unlock"]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct StderrLock<'a> {
inner: ReentrantMutexGuard<'a, RefCell<StderrRaw>>,
Expand Down

0 comments on commit 90afb75

Please sign in to comment.