Skip to content
/ rust Public
forked from rust-lang/rust

Commit e0732e4

Browse files
committed
Use generic NonZero everywhere in std.
1 parent 14ed426 commit e0732e4

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

library/std/src/io/error/repr_bitpacked.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
//! union Repr {
7474
//! // holds integer (Simple/Os) variants, and
7575
//! // provides access to the tag bits.
76-
//! bits: NonZeroU64,
76+
//! bits: NonZero<u64>,
7777
//! // Tag is 0, so this is stored untagged.
7878
//! msg: &'static SimpleMessage,
7979
//! // Tagged (offset) `Box<Custom>` pointer.
@@ -93,7 +93,7 @@
9393
//! `io::Result<()>` and `io::Result<usize>` larger, which defeats part of
9494
//! the motivation of this bitpacking.
9595
//!
96-
//! Storing everything in a `NonZeroUsize` (or some other integer) would be a
96+
//! Storing everything in a `NonZero<usize>` (or some other integer) would be a
9797
//! bit more traditional for pointer tagging, but it would lose provenance
9898
//! information, couldn't be constructed from a `const fn`, and would probably
9999
//! run into other issues as well.

library/std/src/process.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ use crate::ffi::OsStr;
111111
use crate::fmt;
112112
use crate::fs;
113113
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
114-
use crate::num::NonZeroI32;
114+
use crate::num::NonZero;
115115
use crate::path::Path;
116116
use crate::str;
117117
use crate::sys::pipe::{read2, AnonPipe};
@@ -1775,9 +1775,9 @@ impl ExitStatusError {
17751775
self.code_nonzero().map(Into::into)
17761776
}
17771777

1778-
/// Reports the exit code, if applicable, from an `ExitStatusError`, as a `NonZero`
1778+
/// Reports the exit code, if applicable, from an `ExitStatusError`, as a [`NonZero`].
17791779
///
1780-
/// This is exactly like [`code()`](Self::code), except that it returns a `NonZeroI32`.
1780+
/// This is exactly like [`code()`](Self::code), except that it returns a <code>[NonZero]<[i32]></code>.
17811781
///
17821782
/// Plain `code`, returning a plain integer, is provided because it is often more convenient.
17831783
/// The returned value from `code()` is indeed also nonzero; use `code_nonzero()` when you want
@@ -1786,17 +1786,17 @@ impl ExitStatusError {
17861786
/// # Examples
17871787
///
17881788
/// ```
1789-
/// #![feature(exit_status_error)]
1789+
/// #![feature(exit_status_error, generic_nonzero)]
17901790
/// # if cfg!(unix) {
1791-
/// use std::num::NonZeroI32;
1791+
/// use std::num::NonZero;
17921792
/// use std::process::Command;
17931793
///
17941794
/// let bad = Command::new("false").status().unwrap().exit_ok().unwrap_err();
1795-
/// assert_eq!(bad.code_nonzero().unwrap(), NonZeroI32::try_from(1).unwrap());
1795+
/// assert_eq!(bad.code_nonzero().unwrap(), NonZero::new(1).unwrap());
17961796
/// # } // cfg!(unix)
17971797
/// ```
17981798
#[must_use]
1799-
pub fn code_nonzero(&self) -> Option<NonZeroI32> {
1799+
pub fn code_nonzero(&self) -> Option<NonZero<i32>> {
18001800
self.0.code()
18011801
}
18021802

library/std/src/thread/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ use crate::fmt;
165165
use crate::io;
166166
use crate::marker::PhantomData;
167167
use crate::mem::{self, forget};
168-
use crate::num::{NonZero, NonZeroU64, NonZeroUsize};
168+
use crate::num::NonZero;
169169
use crate::panic;
170170
use crate::panicking;
171171
use crate::pin::Pin;
@@ -1222,7 +1222,7 @@ impl ThreadId {
12221222
/// change across Rust versions.
12231223
#[must_use]
12241224
#[unstable(feature = "thread_id_value", issue = "67939")]
1225-
pub fn as_u64(&self) -> NonZeroU64 {
1225+
pub fn as_u64(&self) -> NonZero<u64> {
12261226
self.0
12271227
}
12281228
}
@@ -1784,6 +1784,6 @@ fn _assert_sync_and_send() {
17841784
#[doc(alias = "hardware_concurrency")] // Alias for C++ `std::thread::hardware_concurrency`.
17851785
#[doc(alias = "num_cpus")] // Alias for a popular ecosystem crate which provides similar functionality.
17861786
#[stable(feature = "available_parallelism", since = "1.59.0")]
1787-
pub fn available_parallelism() -> io::Result<NonZeroUsize> {
1787+
pub fn available_parallelism() -> io::Result<NonZero<usize>> {
17881788
imp::available_parallelism()
17891789
}

0 commit comments

Comments
 (0)