Skip to content

Commit c394624

Browse files
committed
Ignore unnecessary unsafe warnings
This is a work-around for a libc issue: rust-lang/libc#1888.
1 parent 7c3e1ff commit c394624

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

library/std/src/sys/unix/fd.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ mod tests;
66
use crate::cmp;
77
use crate::io::{self, Initializer, IoSlice, IoSliceMut, Read};
88
use crate::mem;
9-
#[cfg(not(any(target_os = "redox", target_env = "newlib")))]
109
use crate::sys::cvt;
1110
use crate::sys_common::AsInner;
1211

library/std/src/sys/unix/process/process_unix.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -459,18 +459,38 @@ impl ExitStatus {
459459
}
460460

461461
fn exited(&self) -> bool {
462-
unsafe { libc::WIFEXITED(self.0) }
462+
// On Linux-like OSes this function is safe, on others it is not. See
463+
// libc issue: https://github.com/rust-lang/libc/issues/1888.
464+
#[cfg_attr(
465+
any(target_os = "linux", target_os = "android", target_os = "emscripten"),
466+
allow(unused_unsafe)
467+
)]
468+
unsafe {
469+
libc::WIFEXITED(self.0)
470+
}
463471
}
464472

465473
pub fn success(&self) -> bool {
466474
self.code() == Some(0)
467475
}
468476

469477
pub fn code(&self) -> Option<i32> {
478+
// On Linux-like OSes this function is safe, on others it is not. See
479+
// libc issue: https://github.com/rust-lang/libc/issues/1888.
480+
#[cfg_attr(
481+
any(target_os = "linux", target_os = "android", target_os = "emscripten"),
482+
allow(unused_unsafe)
483+
)]
470484
if self.exited() { Some(unsafe { libc::WEXITSTATUS(self.0) }) } else { None }
471485
}
472486

473487
pub fn signal(&self) -> Option<i32> {
488+
// On Linux-like OSes this function is safe, on others it is not. See
489+
// libc issue: https://github.com/rust-lang/libc/issues/1888.
490+
#[cfg_attr(
491+
any(target_os = "linux", target_os = "android", target_os = "emscripten"),
492+
allow(unused_unsafe)
493+
)]
474494
if !self.exited() { Some(unsafe { libc::WTERMSIG(self.0) }) } else { None }
475495
}
476496
}

0 commit comments

Comments
 (0)