Skip to content

Commit 739bec2

Browse files
committed
Use generic NonZero internally.
1 parent 5518eaa commit 739bec2

File tree

150 files changed

+654
-605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+654
-605
lines changed

compiler/rustc_abi/src/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use tracing::debug;
77

88
use crate::{
99
Abi, AbiAndPrefAlign, Align, FieldsShape, IndexSlice, IndexVec, Integer, LayoutS, Niche,
10-
NonZeroUsize, Primitive, ReprOptions, Scalar, Size, StructKind, TagEncoding, TargetDataLayout,
10+
NonZero, Primitive, ReprOptions, Scalar, Size, StructKind, TagEncoding, TargetDataLayout,
1111
Variants, WrappingRange,
1212
};
1313

@@ -324,7 +324,7 @@ pub trait LayoutCalculator {
324324

325325
Some(LayoutS {
326326
variants: Variants::Single { index: VariantIdx::new(0) },
327-
fields: FieldsShape::Union(NonZeroUsize::new(only_variant.len())?),
327+
fields: FieldsShape::Union(NonZero::<usize>::new(only_variant.len())?),
328328
abi,
329329
largest_niche: None,
330330
align,

compiler/rustc_abi/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
#![cfg_attr(feature = "nightly", feature(generic_nonzero))]
12
#![cfg_attr(feature = "nightly", feature(step_trait))]
23
#![cfg_attr(feature = "nightly", allow(internal_features))]
34
#![cfg_attr(feature = "nightly", doc(rust_logo))]
45
#![cfg_attr(feature = "nightly", feature(rustdoc_internals))]
56

67
use std::fmt;
7-
use std::num::{NonZeroUsize, ParseIntError};
8+
use std::num::{NonZero, ParseIntError};
89
use std::ops::{Add, AddAssign, Mul, RangeInclusive, Sub};
910
use std::str::FromStr;
1011

@@ -1124,7 +1125,7 @@ pub enum FieldsShape<FieldIdx: Idx> {
11241125
Primitive,
11251126

11261127
/// All fields start at no offset. The `usize` is the field count.
1127-
Union(NonZeroUsize),
1128+
Union(NonZero<usize>),
11281129

11291130
/// Array/vector-like placement, with all fields of identical types.
11301131
Array { stride: Size, count: u64 },

compiler/rustc_attr/src/builtin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_session::parse::feature_err;
1313
use rustc_session::{RustcVersion, Session};
1414
use rustc_span::hygiene::Transparency;
1515
use rustc_span::{symbol::sym, symbol::Symbol, Span};
16-
use std::num::NonZeroU32;
16+
use std::num::NonZero;
1717

1818
use crate::session_diagnostics::{self, IncorrectReprFormatGenericCause};
1919

@@ -113,7 +113,7 @@ pub enum StabilityLevel {
113113
/// Reason for the current stability level.
114114
reason: UnstableReason,
115115
/// Relevant `rust-lang/rust` issue.
116-
issue: Option<NonZeroU32>,
116+
issue: Option<NonZero<u32>>,
117117
is_soft: bool,
118118
/// If part of a feature is stabilized and a new feature is added for the remaining parts,
119119
/// then the `implied_by` attribute is used to indicate which now-stable feature previously
@@ -442,7 +442,7 @@ fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabil
442442
// is a name/value pair string literal.
443443
issue_num = match issue.unwrap().as_str() {
444444
"none" => None,
445-
issue => match issue.parse::<NonZeroU32>() {
445+
issue => match issue.parse::<NonZero<u32>>() {
446446
Ok(num) => Some(num),
447447
Err(err) => {
448448
sess.dcx().emit_err(

compiler/rustc_attr/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![allow(internal_features)]
88
#![feature(rustdoc_internals)]
99
#![doc(rust_logo)]
10+
#![feature(generic_nonzero)]
1011
#![feature(let_chains)]
1112
#![deny(rustc::untranslatable_diagnostic)]
1213
#![deny(rustc::diagnostic_outside_of_impl)]

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! to be const-safe.
66
77
use std::fmt::Write;
8-
use std::num::NonZeroUsize;
8+
use std::num::NonZero;
99

1010
use either::{Left, Right};
1111

@@ -780,7 +780,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
780780
fn visit_union(
781781
&mut self,
782782
op: &OpTy<'tcx, M::Provenance>,
783-
_fields: NonZeroUsize,
783+
_fields: NonZero<usize>,
784784
) -> InterpResult<'tcx> {
785785
// Special check for CTFE validation, preventing `UnsafeCell` inside unions in immutable memory.
786786
if self.ctfe_mode.is_some_and(|c| !c.allow_immutable_unsafe_cell()) {

compiler/rustc_const_eval/src/interpret/visitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::ty;
77
use rustc_target::abi::FieldIdx;
88
use rustc_target::abi::{FieldsShape, VariantIdx, Variants};
99

10-
use std::num::NonZeroUsize;
10+
use std::num::NonZero;
1111

1212
use super::{InterpCx, MPlaceTy, Machine, Projectable};
1313

@@ -43,7 +43,7 @@ pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized {
4343
}
4444
/// Visits the given value as a union. No automatic recursion can happen here.
4545
#[inline(always)]
46-
fn visit_union(&mut self, _v: &Self::V, _fields: NonZeroUsize) -> InterpResult<'tcx> {
46+
fn visit_union(&mut self, _v: &Self::V, _fields: NonZero<usize>) -> InterpResult<'tcx> {
4747
Ok(())
4848
}
4949
/// Visits the given value as the pointer of a `Box`. There is nothing to recurse into.

compiler/rustc_const_eval/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Rust MIR: a lowered representation of Rust.
1111
#![feature(assert_matches)]
1212
#![feature(box_patterns)]
1313
#![feature(decl_macro)]
14+
#![feature(generic_nonzero)]
1415
#![feature(let_chains)]
1516
#![feature(slice_ptr_get)]
1617
#![feature(never_type)]

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#![feature(cfg_match)]
2323
#![feature(core_intrinsics)]
2424
#![feature(extend_one)]
25+
#![feature(generic_nonzero)]
2526
#![feature(hash_raw_entry)]
2627
#![feature(hasher_prefixfree_extras)]
2728
#![feature(lazy_cell)]

compiler/rustc_data_structures/src/stable_hasher.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::fmt;
66
use std::hash::{BuildHasher, Hash, Hasher};
77
use std::marker::PhantomData;
88
use std::mem;
9+
use std::num::NonZero;
910

1011
#[cfg(test)]
1112
mod tests;
@@ -338,14 +339,14 @@ impl<CTX, T> HashStable<CTX> for PhantomData<T> {
338339
fn hash_stable(&self, _ctx: &mut CTX, _hasher: &mut StableHasher) {}
339340
}
340341

341-
impl<CTX> HashStable<CTX> for ::std::num::NonZeroU32 {
342+
impl<CTX> HashStable<CTX> for NonZero<u32> {
342343
#[inline]
343344
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
344345
self.get().hash_stable(ctx, hasher)
345346
}
346347
}
347348

348-
impl<CTX> HashStable<CTX> for ::std::num::NonZeroUsize {
349+
impl<CTX> HashStable<CTX> for NonZero<usize> {
349350
#[inline]
350351
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
351352
self.get().hash_stable(ctx, hasher)

compiler/rustc_data_structures/src/sync/worker_local.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use parking_lot::Mutex;
22
use std::cell::Cell;
33
use std::cell::OnceCell;
4-
use std::num::NonZeroUsize;
4+
use std::num::NonZero;
55
use std::ops::Deref;
66
use std::ptr;
77
use std::sync::Arc;
@@ -31,7 +31,7 @@ impl RegistryId {
3131
}
3232

3333
struct RegistryData {
34-
thread_limit: NonZeroUsize,
34+
thread_limit: NonZero<usize>,
3535
threads: Mutex<usize>,
3636
}
3737

@@ -61,7 +61,7 @@ thread_local! {
6161

6262
impl Registry {
6363
/// Creates a registry which can hold up to `thread_limit` threads.
64-
pub fn new(thread_limit: NonZeroUsize) -> Self {
64+
pub fn new(thread_limit: NonZero<usize>) -> Self {
6565
Registry(Arc::new(RegistryData { thread_limit, threads: Mutex::new(0) }))
6666
}
6767

0 commit comments

Comments
 (0)