Ignore unnecessary unsafe warnings

This is a work-around for a libc issue:
https://github.com/rust-lang/libc/issues/1888.
This commit is contained in:
Thomas de Zeeuw
2020-09-11 19:12:06 +02:00
parent 7c3e1ffd7a
commit c394624471
2 changed files with 21 additions and 2 deletions

View File

@@ -459,7 +459,15 @@ impl ExitStatus {
}
fn exited(&self) -> bool {
unsafe { libc::WIFEXITED(self.0) }
// On Linux-like OSes this function is safe, on others it is not. See
// libc issue: https://github.com/rust-lang/libc/issues/1888.
#[cfg_attr(
any(target_os = "linux", target_os = "android", target_os = "emscripten"),
allow(unused_unsafe)
)]
unsafe {
libc::WIFEXITED(self.0)
}
}
pub fn success(&self) -> bool {
@@ -467,10 +475,22 @@ impl ExitStatus {
}
pub fn code(&self) -> Option<i32> {
// On Linux-like OSes this function is safe, on others it is not. See
// libc issue: https://github.com/rust-lang/libc/issues/1888.
#[cfg_attr(
any(target_os = "linux", target_os = "android", target_os = "emscripten"),
allow(unused_unsafe)
)]
if self.exited() { Some(unsafe { libc::WEXITSTATUS(self.0) }) } else { None }
}
pub fn signal(&self) -> Option<i32> {
// On Linux-like OSes this function is safe, on others it is not. See
// libc issue: https://github.com/rust-lang/libc/issues/1888.
#[cfg_attr(
any(target_os = "linux", target_os = "android", target_os = "emscripten"),
allow(unused_unsafe)
)]
if !self.exited() { Some(unsafe { libc::WTERMSIG(self.0) }) } else { None }
}
}