diff options
| author | bors <bors@rust-lang.org> | 2024-02-16 07:46:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-02-16 07:46:31 +0000 |
| commit | 1be468815cb7c6932fcc7ed3ee81e6a14376c05e (patch) | |
| tree | b0b4d37f0274c53c54e2245a73973c6ba1db47bd /library/std/src/sys | |
| parent | 0f806a9812b62c36bdab08d33c14cf2d3ecf4355 (diff) | |
| parent | a90cc05233858fcd16c3ca0e0b4320fc5ae09af2 (diff) | |
| download | rust-1be468815cb7c6932fcc7ed3ee81e6a14376c05e.tar.gz rust-1be468815cb7c6932fcc7ed3ee81e6a14376c05e.zip | |
Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnay
Use generic `NonZero` internally. Tracking issue: https://github.com/rust-lang/rust/issues/120257
Diffstat (limited to 'library/std/src/sys')
23 files changed, 80 insertions, 80 deletions
diff --git a/library/std/src/sys/pal/hermit/thread.rs b/library/std/src/sys/pal/hermit/thread.rs index 3384906a15e..fee80c02d4a 100644 --- a/library/std/src/sys/pal/hermit/thread.rs +++ b/library/std/src/sys/pal/hermit/thread.rs @@ -5,7 +5,7 @@ use super::thread_local_dtor::run_dtors; use crate::ffi::CStr; use crate::io; use crate::mem; -use crate::num::NonZeroUsize; +use crate::num::NonZero; use crate::ptr; use crate::time::Duration; @@ -97,8 +97,8 @@ impl Thread { } } -pub fn available_parallelism() -> io::Result<NonZeroUsize> { - unsafe { Ok(NonZeroUsize::new_unchecked(abi::get_processor_count())) } +pub fn available_parallelism() -> io::Result<NonZero<usize>> { + unsafe { Ok(NonZero::new_unchecked(abi::get_processor_count())) } } pub mod guard { diff --git a/library/std/src/sys/pal/itron/thread.rs b/library/std/src/sys/pal/itron/thread.rs index ae0f718535b..9c1387bf408 100644 --- a/library/std/src/sys/pal/itron/thread.rs +++ b/library/std/src/sys/pal/itron/thread.rs @@ -11,6 +11,7 @@ use crate::{ ffi::CStr, hint, io, mem::ManuallyDrop, + num::NonZero, ptr::NonNull, sync::atomic::{AtomicUsize, Ordering}, sys::thread_local_dtor::run_dtors, @@ -363,6 +364,6 @@ unsafe fn terminate_and_delete_current_task() -> ! { unsafe { crate::hint::unreachable_unchecked() }; } -pub fn available_parallelism() -> io::Result<crate::num::NonZeroUsize> { +pub fn available_parallelism() -> io::Result<NonZero<usize>> { super::unsupported() } diff --git a/library/std/src/sys/pal/sgx/abi/tls/mod.rs b/library/std/src/sys/pal/sgx/abi/tls/mod.rs index 09c4ab3d3e9..6762a43b483 100644 --- a/library/std/src/sys/pal/sgx/abi/tls/mod.rs +++ b/library/std/src/sys/pal/sgx/abi/tls/mod.rs @@ -3,7 +3,7 @@ mod sync_bitset; use self::sync_bitset::*; use crate::cell::Cell; use crate::mem; -use crate::num::NonZeroUsize; +use crate::num::NonZero; use crate::ptr; use crate::sync::atomic::{AtomicUsize, Ordering}; @@ -30,7 +30,7 @@ extern "C" { #[derive(Copy, Clone)] #[repr(C)] -pub struct Key(NonZeroUsize); +pub struct Key(NonZero<usize>); impl Key { fn to_index(self) -> usize { @@ -38,7 +38,7 @@ impl Key { } fn from_index(index: usize) -> Self { - Key(NonZeroUsize::new(index + 1).unwrap()) + Key(NonZero::new(index + 1).unwrap()) } pub fn as_usize(self) -> usize { @@ -46,7 +46,7 @@ impl Key { } pub fn from_usize(index: usize) -> Self { - Key(NonZeroUsize::new(index).unwrap()) + Key(NonZero::new(index).unwrap()) } } diff --git a/library/std/src/sys/pal/sgx/abi/usercalls/raw.rs b/library/std/src/sys/pal/sgx/abi/usercalls/raw.rs index 10c1456d4fd..943b771498f 100644 --- a/library/std/src/sys/pal/sgx/abi/usercalls/raw.rs +++ b/library/std/src/sys/pal/sgx/abi/usercalls/raw.rs @@ -3,14 +3,15 @@ #[unstable(feature = "sgx_platform", issue = "56975")] pub use fortanix_sgx_abi::*; -use crate::num::NonZeroU64; +use crate::num::NonZero; use crate::ptr::NonNull; #[repr(C)] struct UsercallReturn(u64, u64); extern "C" { - fn usercall(nr: NonZeroU64, p1: u64, p2: u64, abort: u64, p3: u64, p4: u64) -> UsercallReturn; + fn usercall(nr: NonZero<u64>, p1: u64, p2: u64, abort: u64, p3: u64, p4: u64) + -> UsercallReturn; } /// Performs the raw usercall operation as defined in the ABI calling convention. @@ -26,7 +27,7 @@ extern "C" { #[unstable(feature = "sgx_platform", issue = "56975")] #[inline] pub unsafe fn do_usercall( - nr: NonZeroU64, + nr: NonZero<u64>, p1: u64, p2: u64, p3: u64, @@ -194,7 +195,7 @@ macro_rules! enclave_usercalls_internal_define_usercalls { #[inline(always)] pub unsafe fn $f($n1: $t1, $n2: $t2, $n3: $t3, $n4: $t4) -> $r { ReturnValue::from_registers(stringify!($f), unsafe { do_usercall( - rtunwrap!(Some, NonZeroU64::new(Usercalls::$f as Register)), + rtunwrap!(Some, NonZero::new(Usercalls::$f as Register)), RegisterArgument::into_register($n1), RegisterArgument::into_register($n2), RegisterArgument::into_register($n3), @@ -210,7 +211,7 @@ macro_rules! enclave_usercalls_internal_define_usercalls { #[inline(always)] pub unsafe fn $f($n1: $t1, $n2: $t2, $n3: $t3) -> $r { ReturnValue::from_registers(stringify!($f), unsafe { do_usercall( - rtunwrap!(Some, NonZeroU64::new(Usercalls::$f as Register)), + rtunwrap!(Some, NonZero::new(Usercalls::$f as Register)), RegisterArgument::into_register($n1), RegisterArgument::into_register($n2), RegisterArgument::into_register($n3), @@ -226,7 +227,7 @@ macro_rules! enclave_usercalls_internal_define_usercalls { #[inline(always)] pub unsafe fn $f($n1: $t1, $n2: $t2) -> $r { ReturnValue::from_registers(stringify!($f), unsafe { do_usercall( - rtunwrap!(Some, NonZeroU64::new(Usercalls::$f as Register)), + rtunwrap!(Some, NonZero::new(Usercalls::$f as Register)), RegisterArgument::into_register($n1), RegisterArgument::into_register($n2), 0,0, @@ -241,7 +242,7 @@ macro_rules! enclave_usercalls_internal_define_usercalls { #[inline(always)] pub unsafe fn $f($n1: $t1) -> $r { ReturnValue::from_registers(stringify!($f), unsafe { do_usercall( - rtunwrap!(Some, NonZeroU64::new(Usercalls::$f as Register)), + rtunwrap!(Some, NonZero::new(Usercalls::$f as Register)), RegisterArgument::into_register($n1), 0,0,0, return_type_is_abort!($r) @@ -255,7 +256,7 @@ macro_rules! enclave_usercalls_internal_define_usercalls { #[inline(always)] pub unsafe fn $f() -> $r { ReturnValue::from_registers(stringify!($f), unsafe { do_usercall( - rtunwrap!(Some, NonZeroU64::new(Usercalls::$f as Register)), + rtunwrap!(Some, NonZero::new(Usercalls::$f as Register)), 0,0,0,0, return_type_is_abort!($r) ) }) diff --git a/library/std/src/sys/pal/sgx/rwlock.rs b/library/std/src/sys/pal/sgx/rwlock.rs index d89de18ca5f..ebae1cff0ee 100644 --- a/library/std/src/sys/pal/sgx/rwlock.rs +++ b/library/std/src/sys/pal/sgx/rwlock.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests; -use crate::num::NonZeroUsize; +use crate::num::NonZero; use crate::sys_common::lazy_box::{LazyBox, LazyInit}; use super::waitqueue::{ @@ -10,7 +10,7 @@ use super::waitqueue::{ use crate::alloc::Layout; struct AllocatedRwLock { - readers: SpinMutex<WaitVariable<Option<NonZeroUsize>>>, + readers: SpinMutex<WaitVariable<Option<NonZero<usize>>>>, writer: SpinMutex<WaitVariable<bool>>, } @@ -53,8 +53,7 @@ impl RwLock { // Another thread has passed the lock to us } else { // No waiting writers, acquire the read lock - *rguard.lock_var_mut() = - NonZeroUsize::new(rguard.lock_var().map_or(0, |n| n.get()) + 1); + *rguard.lock_var_mut() = NonZero::new(rguard.lock_var().map_or(0, |n| n.get()) + 1); } } @@ -68,8 +67,7 @@ impl RwLock { false } else { // No waiting writers, acquire the read lock - *rguard.lock_var_mut() = - NonZeroUsize::new(rguard.lock_var().map_or(0, |n| n.get()) + 1); + *rguard.lock_var_mut() = NonZero::new(rguard.lock_var().map_or(0, |n| n.get()) + 1); true } } @@ -108,10 +106,10 @@ impl RwLock { #[inline] unsafe fn __read_unlock( &self, - mut rguard: SpinMutexGuard<'_, WaitVariable<Option<NonZeroUsize>>>, + mut rguard: SpinMutexGuard<'_, WaitVariable<Option<NonZero<usize>>>>, wguard: SpinMutexGuard<'_, WaitVariable<bool>>, ) { - *rguard.lock_var_mut() = NonZeroUsize::new(rguard.lock_var().unwrap().get() - 1); + *rguard.lock_var_mut() = NonZero::new(rguard.lock_var().unwrap().get() - 1); if rguard.lock_var().is_some() { // There are other active readers } else { @@ -137,7 +135,7 @@ impl RwLock { #[inline] unsafe fn __write_unlock( &self, - rguard: SpinMutexGuard<'_, WaitVariable<Option<NonZeroUsize>>>, + rguard: SpinMutexGuard<'_, WaitVariable<Option<NonZero<usize>>>>, wguard: SpinMutexGuard<'_, WaitVariable<bool>>, ) { match WaitQueue::notify_one(wguard) { diff --git a/library/std/src/sys/pal/sgx/thread.rs b/library/std/src/sys/pal/sgx/thread.rs index 7ac9d1d64b4..c797fde7fbd 100644 --- a/library/std/src/sys/pal/sgx/thread.rs +++ b/library/std/src/sys/pal/sgx/thread.rs @@ -2,7 +2,7 @@ use super::unsupported; use crate::ffi::CStr; use crate::io; -use crate::num::NonZeroUsize; +use crate::num::NonZero; use crate::time::Duration; use super::abi::usercalls; @@ -142,7 +142,7 @@ impl Thread { } } -pub fn available_parallelism() -> io::Result<NonZeroUsize> { +pub fn available_parallelism() -> io::Result<NonZero<usize>> { unsupported() } diff --git a/library/std/src/sys/pal/sgx/waitqueue/mod.rs b/library/std/src/sys/pal/sgx/waitqueue/mod.rs index 25eca61d67b..2d952b7ebbc 100644 --- a/library/std/src/sys/pal/sgx/waitqueue/mod.rs +++ b/library/std/src/sys/pal/sgx/waitqueue/mod.rs @@ -16,7 +16,7 @@ mod tests; mod spin_mutex; mod unsafe_list; -use crate::num::NonZeroUsize; +use crate::num::NonZero; use crate::ops::{Deref, DerefMut}; use crate::panic::{self, AssertUnwindSafe}; use crate::time::Duration; @@ -68,7 +68,7 @@ impl<T> WaitVariable<T> { #[derive(Copy, Clone)] pub enum NotifiedTcs { Single(Tcs), - All { count: NonZeroUsize }, + All { count: NonZero<usize> }, } /// An RAII guard that will notify a set of target threads as well as unlock @@ -252,7 +252,7 @@ impl WaitQueue { entry_guard.wake = true; } - if let Some(count) = NonZeroUsize::new(count) { + if let Some(count) = NonZero::new(count) { Ok(WaitGuard { mutex_guard: Some(guard), notified_tcs: NotifiedTcs::All { count } }) } else { Err(guard) diff --git a/library/std/src/sys/pal/teeos/thread.rs b/library/std/src/sys/pal/teeos/thread.rs index 155f333f906..77f9040ead5 100644 --- a/library/std/src/sys/pal/teeos/thread.rs +++ b/library/std/src/sys/pal/teeos/thread.rs @@ -4,7 +4,7 @@ use crate::cmp; use crate::ffi::CStr; use crate::io; use crate::mem; -use crate::num::NonZeroUsize; +use crate::num::NonZero; use crate::ptr; use crate::sys::os; use crate::time::Duration; @@ -140,7 +140,7 @@ impl Drop for Thread { // Note: Both `sched_getaffinity` and `sysconf` are available but not functional on // teeos, so this function always returns an Error! -pub fn available_parallelism() -> io::Result<NonZeroUsize> { +pub fn available_parallelism() -> io::Result<NonZero<usize>> { Err(io::Error::new( io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform", diff --git a/library/std/src/sys/pal/uefi/thread.rs b/library/std/src/sys/pal/uefi/thread.rs index ddfc3af2f50..3d8fa27251f 100644 --- a/library/std/src/sys/pal/uefi/thread.rs +++ b/library/std/src/sys/pal/uefi/thread.rs @@ -1,7 +1,7 @@ use super::unsupported; use crate::ffi::CStr; use crate::io; -use crate::num::NonZeroUsize; +use crate::num::NonZero; use crate::ptr::NonNull; use crate::time::Duration; @@ -44,9 +44,9 @@ impl Thread { } } -pub fn available_parallelism() -> io::Result<NonZeroUsize> { +pub fn available_parallelism() -> io::Result<NonZero<usize>> { // UEFI is single threaded - Ok(NonZeroUsize::new(1).unwrap()) + Ok(NonZero::new(1).unwrap()) } pub mod guard { diff --git a/library/std/src/sys/pal/unix/process/process_common/tests.rs b/library/std/src/sys/pal/unix/process/process_common/tests.rs index 4e41efc9096..823b4a56336 100644 --- a/library/std/src/sys/pal/unix/process/process_common/tests.rs +++ b/library/std/src/sys/pal/unix/process/process_common/tests.rs @@ -170,7 +170,7 @@ fn test_program_kind() { )))] #[test] fn unix_exit_statuses() { - use crate::num::NonZeroI32; + use crate::num::NonZero; use crate::os::unix::process::ExitStatusExt; use crate::process::*; @@ -182,7 +182,7 @@ fn unix_exit_statuses() { assert_eq!(exit_status.code(), Some(exit_code)); - if let Ok(nz) = NonZeroI32::try_from(exit_code) { + if let Ok(nz) = NonZero::try_from(exit_code) { assert!(!exit_status.success()); let es_error = exit_status.exit_ok().unwrap_err(); assert_eq!(es_error.code().unwrap(), i32::from(nz)); diff --git a/library/std/src/sys/pal/unix/process/process_fuchsia.rs b/library/std/src/sys/pal/unix/process/process_fuchsia.rs index 9931c2af2f1..b6a74fb4831 100644 --- a/library/std/src/sys/pal/unix/process/process_fuchsia.rs +++ b/library/std/src/sys/pal/unix/process/process_fuchsia.rs @@ -1,7 +1,7 @@ use crate::fmt; use crate::io; use crate::mem; -use crate::num::{NonZeroI32, NonZeroI64}; +use crate::num::NonZero; use crate::ptr; use crate::sys::process::process_common::*; @@ -240,7 +240,7 @@ pub struct ExitStatus(i64); impl ExitStatus { pub fn exit_ok(&self) -> Result<(), ExitStatusError> { - match NonZeroI64::try_from(self.0) { + match NonZero::try_from(self.0) { /* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)), /* was zero, couldn't convert */ Err(_) => Ok(()), } @@ -314,7 +314,7 @@ impl fmt::Display for ExitStatus { } #[derive(PartialEq, Eq, Clone, Copy, Debug)] -pub struct ExitStatusError(NonZeroI64); +pub struct ExitStatusError(NonZero<i64>); impl Into<ExitStatus> for ExitStatusError { fn into(self) -> ExitStatus { @@ -323,7 +323,7 @@ impl Into<ExitStatus> for ExitStatusError { } impl ExitStatusError { - pub fn code(self) -> Option<NonZeroI32> { + pub fn code(self) -> Option<NonZero<i32>> { // fixme: affected by the same bug as ExitStatus::code() ExitStatus(self.0.into()).code().map(|st| st.try_into().unwrap()) } diff --git a/library/std/src/sys/pal/unix/process/process_unix.rs b/library/std/src/sys/pal/unix/process/process_unix.rs index 94c4c56bd51..d5a77085725 100644 --- a/library/std/src/sys/pal/unix/process/process_unix.rs +++ b/library/std/src/sys/pal/unix/process/process_unix.rs @@ -1,7 +1,7 @@ use crate::fmt; use crate::io::{self, Error, ErrorKind}; use crate::mem; -use crate::num::{NonZero, NonZeroI32}; +use crate::num::NonZero; use crate::sys; use crate::sys::cvt; use crate::sys::process::process_common::*; @@ -1106,7 +1106,7 @@ impl fmt::Debug for ExitStatusError { } impl ExitStatusError { - pub fn code(self) -> Option<NonZeroI32> { + pub fn code(self) -> Option<NonZero<i32>> { ExitStatus(self.0.into()).code().map(|st| st.try_into().unwrap()) } } diff --git a/library/std/src/sys/pal/unix/process/process_unsupported.rs b/library/std/src/sys/pal/unix/process/process_unsupported.rs index 89a2a0c6e56..33d359d3f84 100644 --- a/library/std/src/sys/pal/unix/process/process_unsupported.rs +++ b/library/std/src/sys/pal/unix/process/process_unsupported.rs @@ -1,6 +1,6 @@ use crate::fmt; use crate::io; -use crate::num::{NonZero, NonZeroI32}; +use crate::num::NonZero; use crate::sys::pal::unix::unsupported::*; use crate::sys::process::process_common::*; @@ -67,7 +67,7 @@ impl Into<ExitStatus> for ExitStatusError { } impl ExitStatusError { - pub fn code(self) -> Option<NonZeroI32> { + pub fn code(self) -> Option<NonZero<i32>> { ExitStatus::from(c_int::from(self.0)).code().map(|st| st.try_into().unwrap()) } } diff --git a/library/std/src/sys/pal/unix/process/process_vxworks.rs b/library/std/src/sys/pal/unix/process/process_vxworks.rs index 5b4e94d0f1b..76179e0910d 100644 --- a/library/std/src/sys/pal/unix/process/process_vxworks.rs +++ b/library/std/src/sys/pal/unix/process/process_vxworks.rs @@ -1,6 +1,6 @@ use crate::fmt; use crate::io::{self, Error, ErrorKind}; -use crate::num::{NonZero, NonZeroI32}; +use crate::num::NonZero; use crate::sys; use crate::sys::cvt; use crate::sys::process::process_common::*; @@ -257,7 +257,7 @@ impl Into<ExitStatus> for ExitStatusError { } impl ExitStatusError { - pub fn code(self) -> Option<NonZeroI32> { + pub fn code(self) -> Option<NonZero<i32>> { ExitStatus(self.0.into()).code().map(|st| st.try_into().unwrap()) } } diff --git a/library/std/src/sys/pal/unix/thread.rs b/library/std/src/sys/pal/unix/thread.rs index ba8d31c23a5..97976407bb4 100644 --- a/library/std/src/sys/pal/unix/thread.rs +++ b/library/std/src/sys/pal/unix/thread.rs @@ -2,7 +2,7 @@ use crate::cmp; use crate::ffi::CStr; use crate::io; use crate::mem; -use crate::num::NonZeroUsize; +use crate::num::NonZero; use crate::ptr; use crate::sys::{os, stack_overflow}; use crate::time::Duration; @@ -306,7 +306,7 @@ fn truncate_cstr<const MAX_WITH_NUL: usize>(cstr: &CStr) -> [libc::c_char; MAX_W result } -pub fn available_parallelism() -> io::Result<NonZeroUsize> { +pub fn available_parallelism() -> io::Result<NonZero<usize>> { cfg_if::cfg_if! { if #[cfg(any( target_os = "android", @@ -338,7 +338,7 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> { // some old MIPS kernels were buggy and zero-initialized the mask if // none was explicitly set. // In that case we use the sysconf fallback. - if let Some(count) = NonZeroUsize::new(count) { + if let Some(count) = NonZero::new(count) { return Ok(count) } } @@ -351,7 +351,7 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> { let count = cpus as usize; // Cover the unusual situation where we were able to get the quota but not the affinity mask let count = count.min(quota); - Ok(unsafe { NonZeroUsize::new_unchecked(count) }) + Ok(unsafe { NonZero::new_unchecked(count) }) } } } else if #[cfg(any( @@ -375,7 +375,7 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> { ) == 0 { let count = libc::CPU_COUNT(&set) as usize; if count > 0 { - return Ok(NonZeroUsize::new_unchecked(count)); + return Ok(NonZero::new_unchecked(count)); } } } @@ -397,7 +397,7 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> { } } libc::_cpuset_destroy(set); - if let Some(count) = NonZeroUsize::new(count) { + if let Some(count) = NonZero::new(count) { return Ok(count); } } @@ -433,7 +433,7 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> { } } - Ok(unsafe { NonZeroUsize::new_unchecked(cpus as usize) }) + Ok(unsafe { NonZero::new_unchecked(cpus as usize) }) } else if #[cfg(target_os = "nto")] { unsafe { use libc::_syspage_ptr; @@ -441,7 +441,7 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> { Err(io::const_io_error!(io::ErrorKind::NotFound, "No syspage available")) } else { let cpus = (*_syspage_ptr).num_cpu; - NonZeroUsize::new(cpus as usize) + NonZero::new(cpus as usize) .ok_or(io::const_io_error!(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform")) } } @@ -456,7 +456,7 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> { return Err(io::const_io_error!(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform")); } - Ok(NonZeroUsize::new_unchecked(sinfo.cpu_count as usize)) + Ok(NonZero::new_unchecked(sinfo.cpu_count as usize)) } } else { // FIXME: implement on vxWorks, Redox, l4re diff --git a/library/std/src/sys/pal/unsupported/process.rs b/library/std/src/sys/pal/unsupported/process.rs index a639afcc674..6a989dd3e76 100644 --- a/library/std/src/sys/pal/unsupported/process.rs +++ b/library/std/src/sys/pal/unsupported/process.rs @@ -2,7 +2,7 @@ use crate::ffi::OsStr; use crate::fmt; use crate::io; use crate::marker::PhantomData; -use crate::num::NonZeroI32; +use crate::num::NonZero; use crate::path::Path; use crate::sys::fs::File; use crate::sys::pipe::AnonPipe; @@ -170,7 +170,7 @@ impl Into<ExitStatus> for ExitStatusError { } impl ExitStatusError { - pub fn code(self) -> Option<NonZeroI32> { + pub fn code(self) -> Option<NonZero<i32>> { self.0 } } diff --git a/library/std/src/sys/pal/unsupported/thread.rs b/library/std/src/sys/pal/unsupported/thread.rs index a8db251de20..cd1ae7f7d11 100644 --- a/library/std/src/sys/pal/unsupported/thread.rs +++ b/library/std/src/sys/pal/unsupported/thread.rs @@ -1,7 +1,7 @@ use super::unsupported; use crate::ffi::CStr; use crate::io; -use crate::num::NonZeroUsize; +use crate::num::NonZero; use crate::time::Duration; pub struct Thread(!); @@ -31,7 +31,7 @@ impl Thread { } } -pub fn available_parallelism() -> io::Result<NonZeroUsize> { +pub fn available_parallelism() -> io::Result<NonZero<usize>> { unsupported() } diff --git a/library/std/src/sys/pal/wasi/thread.rs b/library/std/src/sys/pal/wasi/thread.rs index a0eefa8811a..77d8b4378e7 100644 --- a/library/std/src/sys/pal/wasi/thread.rs +++ b/library/std/src/sys/pal/wasi/thread.rs @@ -1,7 +1,7 @@ use crate::ffi::CStr; use crate::io; use crate::mem; -use crate::num::NonZeroUsize; +use crate::num::NonZero; use crate::sys::unsupported; use crate::time::Duration; @@ -186,7 +186,7 @@ impl Thread { } } -pub fn available_parallelism() -> io::Result<NonZeroUsize> { +pub fn available_parallelism() -> io::Result<NonZero<usize>> { unsupported() } diff --git a/library/std/src/sys/pal/wasm/atomics/thread.rs b/library/std/src/sys/pal/wasm/atomics/thread.rs index 714b7049227..49f936f1449 100644 --- a/library/std/src/sys/pal/wasm/atomics/thread.rs +++ b/library/std/src/sys/pal/wasm/atomics/thread.rs @@ -1,6 +1,6 @@ use crate::ffi::CStr; use crate::io; -use crate::num::NonZeroUsize; +use crate::num::NonZero; use crate::sys::unsupported; use crate::time::Duration; @@ -40,7 +40,7 @@ impl Thread { pub fn join(self) {} } -pub fn available_parallelism() -> io::Result<NonZeroUsize> { +pub fn available_parallelism() -> io::Result<NonZero<usize>> { unsupported() } diff --git a/library/std/src/sys/pal/windows/args.rs b/library/std/src/sys/pal/windows/args.rs index fbbdbc21265..2ecfe088d10 100644 --- a/library/std/src/sys/pal/windows/args.rs +++ b/library/std/src/sys/pal/windows/args.rs @@ -10,7 +10,7 @@ use super::os::current_exe; use crate::ffi::OsString; use crate::fmt; use crate::io; -use crate::num::NonZeroU16; +use crate::num::NonZero; use crate::os::windows::prelude::*; use crate::path::{Path, PathBuf}; use crate::sys::path::get_long_path; @@ -21,12 +21,12 @@ use crate::vec; use crate::iter; -/// This is the const equivalent to `NonZeroU16::new(n).unwrap()` +/// This is the const equivalent to `NonZero::new(n).unwrap()` /// /// FIXME: This can be removed once `Option::unwrap` is stably const. /// See the `const_option` feature (#67441). -const fn non_zero_u16(n: u16) -> NonZeroU16 { - match NonZeroU16::new(n) { +const fn non_zero_u16(n: u16) -> NonZero<u16> { + match NonZero::new(n) { Some(n) => n, None => panic!("called `unwrap` on a `None` value"), } @@ -69,10 +69,10 @@ fn parse_lp_cmd_line<'a, F: Fn() -> OsString>( lp_cmd_line: Option<WStrUnits<'a>>, exe_name: F, ) -> Vec<OsString> { - const BACKSLASH: NonZeroU16 = non_zero_u16(b'\\' as u16); - const QUOTE: NonZeroU16 = non_zero_u16(b'"' as u16); - const TAB: NonZeroU16 = non_zero_u16(b'\t' as u16); - const SPACE: NonZeroU16 = non_zero_u16(b' ' as u16); + const BACKSLASH: NonZero<u16> = non_zero_u16(b'\\' as u16); + const QUOTE: NonZero<u16> = non_zero_u16(b'"' as u16); + const TAB: NonZero<u16> = non_zero_u16(b'\t' as u16); + const SPACE: NonZero<u16> = non_zero_u16(b' ' as u16); let mut ret_val = Vec::new(); // If the cmd line pointer is null or it points to an empty string then diff --git a/library/std/src/sys/pal/windows/process.rs b/library/std/src/sys/pal/windows/process.rs index 9ec775959fd..6a94d377140 100644 --- a/library/std/src/sys/pal/windows/process.rs +++ b/library/std/src/sys/pal/windows/process.rs @@ -12,7 +12,7 @@ use crate::fmt; use crate::io::{self, Error, ErrorKind}; use crate::mem; use crate::mem::MaybeUninit; -use crate::num::NonZeroI32; +use crate::num::NonZero; use crate::os::windows::ffi::{OsStrExt, OsStringExt}; use crate::os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle, FromRawHandle, IntoRawHandle}; use crate::path::{Path, PathBuf}; @@ -747,7 +747,7 @@ impl Into<ExitStatus> for ExitStatusError { } impl ExitStatusError { - pub fn code(self) -> Option<NonZeroI32> { + pub fn code(self) -> Option<NonZero<i32>> { Some((u32::from(self.0) as i32).try_into().unwrap()) } } diff --git a/library/std/src/sys/pal/windows/thread.rs b/library/std/src/sys/pal/windows/thread.rs index 1fe74493519..0f709e2ec7b 100644 --- a/library/std/src/sys/pal/windows/thread.rs +++ b/library/std/src/sys/pal/windows/thread.rs @@ -1,6 +1,6 @@ use crate::ffi::CStr; use crate::io; -use crate::num::NonZeroUsize; +use crate::num::NonZero; use crate::os::windows::io::AsRawHandle; use crate::os::windows::io::HandleOrNull; use crate::ptr; @@ -110,7 +110,7 @@ impl Thread { } } -pub fn available_parallelism() -> io::Result<NonZeroUsize> { +pub fn available_parallelism() -> io::Result<NonZero<usize>> { let res = unsafe { let mut sysinfo: c::SYSTEM_INFO = crate::mem::zeroed(); c::GetSystemInfo(&mut sysinfo); @@ -121,7 +121,7 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> { io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform", )), - cpus => Ok(unsafe { NonZeroUsize::new_unchecked(cpus) }), + cpus => Ok(unsafe { NonZero::new_unchecked(cpus) }), } } diff --git a/library/std/src/sys/pal/xous/thread.rs b/library/std/src/sys/pal/xous/thread.rs index 0f452e07a5c..21f5954d6e2 100644 --- a/library/std/src/sys/pal/xous/thread.rs +++ b/library/std/src/sys/pal/xous/thread.rs @@ -1,6 +1,6 @@ use crate::ffi::CStr; use crate::io; -use crate::num::NonZeroUsize; +use crate::num::NonZero; use crate::os::xous::ffi::{ blocking_scalar, create_thread, do_yield, join_thread, map_memory, update_memory_flags, MemoryFlags, Syscall, ThreadId, @@ -132,9 +132,9 @@ impl Thread { } } -pub fn available_parallelism() -> io::Result<NonZeroUsize> { +pub fn available_parallelism() -> io::Result<NonZero<usize>> { // We're unicore right now. - Ok(unsafe { NonZeroUsize::new_unchecked(1) }) + Ok(unsafe { NonZero::new_unchecked(1) }) } pub mod guard { |
