diff options
| author | Markus Reiter <me@reitermark.us> | 2024-02-19 06:02:17 +0100 |
|---|---|---|
| committer | Markus Reiter <me@reitermark.us> | 2024-02-22 15:17:33 +0100 |
| commit | e0732e42d829cd8aa8480811d0c860387437e6ca (patch) | |
| tree | bc2ec64e6b5f516aed3b86feabf03c00a1401bfc | |
| parent | 14ed426eec6939737ea320e50bb28d239c7aee93 (diff) | |
| download | rust-e0732e42d829cd8aa8480811d0c860387437e6ca.tar.gz rust-e0732e42d829cd8aa8480811d0c860387437e6ca.zip | |
Use generic `NonZero` everywhere in `std`.
| -rw-r--r-- | library/std/src/io/error/repr_bitpacked.rs | 4 | ||||
| -rw-r--r-- | library/std/src/process.rs | 14 | ||||
| -rw-r--r-- | library/std/src/thread/mod.rs | 6 |
3 files changed, 12 insertions, 12 deletions
diff --git a/library/std/src/io/error/repr_bitpacked.rs b/library/std/src/io/error/repr_bitpacked.rs index c053e047b1a..6f8d5e37775 100644 --- a/library/std/src/io/error/repr_bitpacked.rs +++ b/library/std/src/io/error/repr_bitpacked.rs @@ -73,7 +73,7 @@ //! union Repr { //! // holds integer (Simple/Os) variants, and //! // provides access to the tag bits. -//! bits: NonZeroU64, +//! bits: NonZero<u64>, //! // Tag is 0, so this is stored untagged. //! msg: &'static SimpleMessage, //! // Tagged (offset) `Box<Custom>` pointer. @@ -93,7 +93,7 @@ //! `io::Result<()>` and `io::Result<usize>` larger, which defeats part of //! the motivation of this bitpacking. //! -//! Storing everything in a `NonZeroUsize` (or some other integer) would be a +//! Storing everything in a `NonZero<usize>` (or some other integer) would be a //! bit more traditional for pointer tagging, but it would lose provenance //! information, couldn't be constructed from a `const fn`, and would probably //! run into other issues as well. diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 669affa266a..b84d5f11954 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -111,7 +111,7 @@ use crate::ffi::OsStr; use crate::fmt; use crate::fs; use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; -use crate::num::NonZeroI32; +use crate::num::NonZero; use crate::path::Path; use crate::str; use crate::sys::pipe::{read2, AnonPipe}; @@ -1775,9 +1775,9 @@ impl ExitStatusError { self.code_nonzero().map(Into::into) } - /// Reports the exit code, if applicable, from an `ExitStatusError`, as a `NonZero` + /// Reports the exit code, if applicable, from an `ExitStatusError`, as a [`NonZero`]. /// - /// This is exactly like [`code()`](Self::code), except that it returns a `NonZeroI32`. + /// This is exactly like [`code()`](Self::code), except that it returns a <code>[NonZero]<[i32]></code>. /// /// Plain `code`, returning a plain integer, is provided because it is often more convenient. /// The returned value from `code()` is indeed also nonzero; use `code_nonzero()` when you want @@ -1786,17 +1786,17 @@ impl ExitStatusError { /// # Examples /// /// ``` - /// #![feature(exit_status_error)] + /// #![feature(exit_status_error, generic_nonzero)] /// # if cfg!(unix) { - /// use std::num::NonZeroI32; + /// use std::num::NonZero; /// use std::process::Command; /// /// let bad = Command::new("false").status().unwrap().exit_ok().unwrap_err(); - /// assert_eq!(bad.code_nonzero().unwrap(), NonZeroI32::try_from(1).unwrap()); + /// assert_eq!(bad.code_nonzero().unwrap(), NonZero::new(1).unwrap()); /// # } // cfg!(unix) /// ``` #[must_use] - pub fn code_nonzero(&self) -> Option<NonZeroI32> { + pub fn code_nonzero(&self) -> Option<NonZero<i32>> { self.0.code() } diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 4f0f010984a..76af7fec926 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -165,7 +165,7 @@ use crate::fmt; use crate::io; use crate::marker::PhantomData; use crate::mem::{self, forget}; -use crate::num::{NonZero, NonZeroU64, NonZeroUsize}; +use crate::num::NonZero; use crate::panic; use crate::panicking; use crate::pin::Pin; @@ -1222,7 +1222,7 @@ impl ThreadId { /// change across Rust versions. #[must_use] #[unstable(feature = "thread_id_value", issue = "67939")] - pub fn as_u64(&self) -> NonZeroU64 { + pub fn as_u64(&self) -> NonZero<u64> { self.0 } } @@ -1784,6 +1784,6 @@ fn _assert_sync_and_send() { #[doc(alias = "hardware_concurrency")] // Alias for C++ `std::thread::hardware_concurrency`. #[doc(alias = "num_cpus")] // Alias for a popular ecosystem crate which provides similar functionality. #[stable(feature = "available_parallelism", since = "1.59.0")] -pub fn available_parallelism() -> io::Result<NonZeroUsize> { +pub fn available_parallelism() -> io::Result<NonZero<usize>> { imp::available_parallelism() } |
