Skip to content

Commit

Permalink
Add SAFETY comments for AsFd implementations on stdin/stdout/stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtriplett authored and sunfishcode committed Oct 3, 2022
1 parent 625ebf6 commit 905ebc3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions library/std/src/sys/wasi/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl AsFd for Stdin {
impl<'a> AsFd for io::StdinLock<'a> {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
// SAFETY: user code should not close stdin out from under the standard library
unsafe { BorrowedFd::borrow_raw(0) }
}
}
Expand Down Expand Up @@ -77,6 +78,7 @@ impl AsFd for Stdout {
impl<'a> AsFd for io::StdoutLock<'a> {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
// SAFETY: user code should not close stdout out from under the standard library
unsafe { BorrowedFd::borrow_raw(1) }
}
}
Expand Down Expand Up @@ -123,6 +125,7 @@ impl AsFd for Stderr {
impl<'a> AsFd for io::StderrLock<'a> {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
// SAFETY: user code should not close stderr out from under the standard library
unsafe { BorrowedFd::borrow_raw(2) }
}
}
Expand Down

0 comments on commit 905ebc3

Please sign in to comment.