Skip to content

Commit fc794e9

Browse files
committed
Fix the assertion in Pid::from_raw to accept 0. (#1456)
* Fix the assertion in `Pid::from_raw` to accept 0. Fix a regression from #1443 which disallowed calling `Pid::from_raw` with the value 0. * Disable transmutes warnings for now. * Add a test. * Update CI to ubuntu-22.04, as ubuntu-20.04 is no longer supported. * Fix the build on Rust 1.63. * Temporarily work around nightly build errors on powerpc64-ibm-aix.
1 parent 5ce17db commit fc794e9

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

.github/workflows/main.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ jobs:
229229
- run: cargo check -Z build-std --target=x86_64-pc-nto-qnx710 --features=all-apis
230230
- run: cargo check -Z build-std --target=armv6k-nintendo-3ds --all-features
231231
- run: cargo check -Z build-std --target=armv7-sony-vita-newlibeabihf --features=all-apis
232-
- run: cargo check -Z build-std --target=powerpc64-ibm-aix --features=all-apis
232+
# Temporarily disable due to build errors on nightly.
233+
# - run: cargo check -Z build-std --target=powerpc64-ibm-aix --features=all-apis
233234
- run: cargo check -Z build-std --target=mipsel-unknown-linux-gnu --features=all-apis
234235
- run: cargo check -Z build-std --target=mips64el-unknown-linux-gnuabi64 --features=all-apis
235236
- run: cargo check -Z build-std --target=powerpc-unknown-linux-musl --features=all-apis
@@ -246,13 +247,13 @@ jobs:
246247
RUSTFLAGS: --cfg rustix_use_experimental_features
247248
strategy:
248249
matrix:
249-
build: [ubuntu, ubuntu-20.04, i686-linux, aarch64-linux, powerpc-linux, powerpc64le-linux, riscv64-linux, s390x-linux, arm-linux, ubuntu-stable, i686-linux-stable, aarch64-linux-stable, riscv64-linux-stable, s390x-linux-stable, powerpc-linux-stable, powerpc64le-linux-stable, arm-linux-stable, ubuntu-1.63, i686-linux-1.63, aarch64-linux-1.63, riscv64-linux-1.63, s390x-linux-1.63, powerpc64le-linux, powerpc64le-linux-1.63, arm-linux-1.63, macos-latest, macos-13, windows, windows-2019, musl]
250+
build: [ubuntu, ubuntu-22.04, i686-linux, aarch64-linux, powerpc-linux, powerpc64le-linux, riscv64-linux, s390x-linux, arm-linux, ubuntu-stable, i686-linux-stable, aarch64-linux-stable, riscv64-linux-stable, s390x-linux-stable, powerpc-linux-stable, powerpc64le-linux-stable, arm-linux-stable, ubuntu-1.63, i686-linux-1.63, aarch64-linux-1.63, riscv64-linux-1.63, s390x-linux-1.63, powerpc64le-linux, powerpc64le-linux-1.63, arm-linux-1.63, macos-latest, macos-13, windows, windows-2019, musl]
250251
include:
251252
- build: ubuntu
252253
os: ubuntu-latest
253254
rust: nightly
254-
- build: ubuntu-20.04
255-
os: ubuntu-20.04
255+
- build: ubuntu-22.04
256+
os: ubuntu-22.04
256257
rust: nightly
257258
- build: i686-linux
258259
os: ubuntu-latest

src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@
122122
#![allow(clippy::useless_conversion)]
123123
// This clippy lint gets too many false positives.
124124
#![allow(clippy::needless_lifetimes)]
125+
// Until `unnecessary_transmutes` is recognized by our MSRV, don't warn about
126+
// it being unrecognized.
127+
#![allow(unknown_lints)]
128+
// Until `cast_signed` and `cast_unsigned` are supported by our MSRV, don't
129+
// warn about transmutes that could be changed to them.
130+
#![allow(unnecessary_transmutes)]
125131
// Redox and WASI have enough differences that it isn't worth precisely
126132
// conditionalizing all the `use`s for them. Similar for if we don't have
127133
// "all-apis".

src/pid.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Pid {
4141
/// [pidfd]: https://man7.org/linux/man-pages/man2/pidfd_open.2.html
4242
#[inline]
4343
pub const fn from_raw(raw: RawPid) -> Option<Self> {
44-
debug_assert!(raw > 0);
44+
debug_assert!(raw >= 0);
4545
match NonZeroI32::new(raw) {
4646
Some(non_zero) => Some(Self(non_zero)),
4747
None => None,
@@ -115,4 +115,21 @@ mod tests {
115115
transmute::<Option<Pid>, RawPid>(Some(Pid::from_raw_unchecked(4567)))
116116
});
117117
}
118+
119+
#[test]
120+
fn test_ctors() {
121+
use std::num::NonZeroI32;
122+
assert!(Pid::from_raw(0).is_none());
123+
assert_eq!(
124+
Pid::from_raw(77).unwrap().as_raw_nonzero(),
125+
NonZeroI32::new(77).unwrap()
126+
);
127+
assert_eq!(Pid::as_raw(Pid::from_raw(77)), 77);
128+
}
129+
130+
#[test]
131+
fn test_specials() {
132+
assert!(Pid::from_raw(1).unwrap().is_init());
133+
assert_eq!(Pid::from_raw(1).unwrap(), Pid::INIT);
134+
}
118135
}

0 commit comments

Comments
 (0)