Skip to content

Commit a90cc05

Browse files
committed
Replace NonZero::<_>::new with NonZero::new.
1 parent 746a58d commit a90cc05

File tree

70 files changed

+175
-216
lines changed

Some content is hidden

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

70 files changed

+175
-216
lines changed

Diff for: compiler/rustc_data_structures/src/tagged_ptr/copy.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,14 @@ where
143143
// `{non_zero} | packed_tag` can't make the value zero.
144144

145145
let packed = (addr.get() >> T::BITS) | packed_tag;
146-
unsafe { NonZero::<usize>::new_unchecked(packed) }
146+
unsafe { NonZero::new_unchecked(packed) }
147147
})
148148
}
149149

150150
/// Retrieves the original raw pointer from `self.packed`.
151151
#[inline]
152152
pub(super) fn pointer_raw(&self) -> NonNull<P::Target> {
153-
self.packed
154-
.map_addr(|addr| unsafe { NonZero::<usize>::new_unchecked(addr.get() << T::BITS) })
153+
self.packed.map_addr(|addr| unsafe { NonZero::new_unchecked(addr.get() << T::BITS) })
155154
}
156155

157156
/// This provides a reference to the `P` pointer itself, rather than the

Diff for: compiler/rustc_feature/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const fn to_nonzero(n: Option<u32>) -> Option<NonZero<u32>> {
105105
// in const context. Requires https://github.com/rust-lang/rfcs/pull/2632.
106106
match n {
107107
None => None,
108-
Some(n) => NonZero::<u32>::new(n),
108+
Some(n) => NonZero::new(n),
109109
}
110110
}
111111

Diff for: compiler/rustc_interface/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ fn test_unstable_options_tracking_hash() {
827827
tracked!(tls_model, Some(TlsModel::GeneralDynamic));
828828
tracked!(translate_remapped_path_to_local_path, false);
829829
tracked!(trap_unreachable, Some(false));
830-
tracked!(treat_err_as_bug, NonZero::<usize>::new(1));
830+
tracked!(treat_err_as_bug, NonZero::new(1));
831831
tracked!(tune_cpu, Some(String::from("abc")));
832832
tracked!(uninit_const_chunk_threshold, 123);
833833
tracked!(unleash_the_miri_inside_of_you, true);

Diff for: compiler/rustc_interface/src/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
107107
use rustc_query_impl::QueryCtxt;
108108
use rustc_query_system::query::{deadlock, QueryContext};
109109

110-
let registry = sync::Registry::new(std::num::NonZero::<usize>::new(threads).unwrap());
110+
let registry = sync::Registry::new(std::num::NonZero::new(threads).unwrap());
111111

112112
if !sync::is_dyn_thread_safe() {
113113
return run_in_thread_with_globals(edition, || {

Diff for: compiler/rustc_metadata/src/rmeta/decoder.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
338338
}
339339
LazyState::Previous(last_pos) => last_pos.get() + distance,
340340
};
341-
let position = NonZero::<usize>::new(position).unwrap();
341+
let position = NonZero::new(position).unwrap();
342342
self.lazy_state = LazyState::Previous(position);
343343
f(position)
344344
}
@@ -685,17 +685,15 @@ impl MetadataBlob {
685685
}
686686

687687
pub(crate) fn get_rustc_version(&self) -> String {
688-
LazyValue::<String>::from_position(
689-
NonZero::<usize>::new(METADATA_HEADER.len() + 8).unwrap(),
690-
)
691-
.decode(self)
688+
LazyValue::<String>::from_position(NonZero::new(METADATA_HEADER.len() + 8).unwrap())
689+
.decode(self)
692690
}
693691

694692
fn root_pos(&self) -> NonZero<usize> {
695693
let offset = METADATA_HEADER.len();
696694
let pos_bytes = self.blob()[offset..][..8].try_into().unwrap();
697695
let pos = u64::from_le_bytes(pos_bytes);
698-
NonZero::<usize>::new(pos as usize).unwrap()
696+
NonZero::new(pos as usize).unwrap()
699697
}
700698

701699
pub(crate) fn get_header(&self) -> CrateHeader {

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
439439
position.get() - last_pos.get()
440440
}
441441
};
442-
self.lazy_state = LazyState::Previous(NonZero::<usize>::new(pos).unwrap());
442+
self.lazy_state = LazyState::Previous(NonZero::new(pos).unwrap());
443443
self.emit_usize(distance);
444444
}
445445

446446
fn lazy<T: ParameterizedOverTcx, B: Borrow<T::Value<'tcx>>>(&mut self, value: B) -> LazyValue<T>
447447
where
448448
T::Value<'tcx>: Encodable<EncodeContext<'a, 'tcx>>,
449449
{
450-
let pos = NonZero::<usize>::new(self.position()).unwrap();
450+
let pos = NonZero::new(self.position()).unwrap();
451451

452452
assert_eq!(self.lazy_state, LazyState::NoNode);
453453
self.lazy_state = LazyState::NodeStart(pos);
@@ -466,7 +466,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
466466
where
467467
T::Value<'tcx>: Encodable<EncodeContext<'a, 'tcx>>,
468468
{
469-
let pos = NonZero::<usize>::new(self.position()).unwrap();
469+
let pos = NonZero::new(self.position()).unwrap();
470470

471471
assert_eq!(self.lazy_state, LazyState::NoNode);
472472
self.lazy_state = LazyState::NodeStart(pos);

Diff for: compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<T: ParameterizedOverTcx> ParameterizedOverTcx for LazyArray<T> {
119119

120120
impl<T> Default for LazyArray<T> {
121121
fn default() -> LazyArray<T> {
122-
LazyArray::from_position_and_num_elems(NonZero::<usize>::new(1).unwrap(), 0)
122+
LazyArray::from_position_and_num_elems(NonZero::new(1).unwrap(), 0)
123123
}
124124
}
125125

Diff for: compiler/rustc_metadata/src/rmeta/table.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl<T> FixedSizeEncoding for Option<LazyValue<T>> {
339339

340340
#[inline]
341341
fn from_bytes(b: &[u8; 8]) -> Self {
342-
let position = NonZero::<usize>::new(u64::from_bytes(b) as usize)?;
342+
let position = NonZero::new(u64::from_bytes(b) as usize)?;
343343
Some(LazyValue::from_position(position))
344344
}
345345

@@ -366,7 +366,7 @@ impl<T> LazyArray<T> {
366366
}
367367

368368
fn from_bytes_impl(position: &[u8; 8], meta: &[u8; 8]) -> Option<LazyArray<T>> {
369-
let position = NonZero::<usize>::new(u64::from_bytes(position) as usize)?;
369+
let position = NonZero::new(u64::from_bytes(position) as usize)?;
370370
let len = u64::from_bytes(meta) as usize;
371371
Some(LazyArray::from_position_and_num_elems(position, len))
372372
}
@@ -497,7 +497,7 @@ impl<I: Idx, const N: usize, T: FixedSizeEncoding<ByteArray = [u8; N]>> TableBui
497497
}
498498

499499
LazyTable::from_position_and_encoded_size(
500-
NonZero::<usize>::new(pos).unwrap(),
500+
NonZero::new(pos).unwrap(),
501501
width,
502502
self.blocks.len(),
503503
)

Diff for: compiler/rustc_middle/src/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl<'tcx> TyCtxt<'tcx> {
433433
// the `-Z force-unstable-if-unmarked` flag present (we're
434434
// compiling a compiler crate), then let this missing feature
435435
// annotation slide.
436-
if feature == sym::rustc_private && issue == NonZero::<u32>::new(27812) {
436+
if feature == sym::rustc_private && issue == NonZero::new(27812) {
437437
if self.sess.opts.unstable_opts.force_unstable_if_unmarked {
438438
return EvalResult::Allow;
439439
}

Diff for: compiler/rustc_middle/src/mir/interpret/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ impl<'tcx> AllocMap<'tcx> {
500500
AllocMap {
501501
alloc_map: Default::default(),
502502
dedup: Default::default(),
503-
next_id: AllocId(NonZero::<u64>::new(1).unwrap()),
503+
next_id: AllocId(NonZero::new(1).unwrap()),
504504
}
505505
}
506506
fn reserve(&mut self) -> AllocId {

Diff for: compiler/rustc_middle/src/mir/interpret/pointer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl CtfeProvenance {
155155
/// Returns the `AllocId` of this provenance.
156156
#[inline(always)]
157157
pub fn alloc_id(self) -> AllocId {
158-
AllocId(NonZero::<u64>::new(self.0.get() & !IMMUTABLE_MASK).unwrap())
158+
AllocId(NonZero::new(self.0.get() & !IMMUTABLE_MASK).unwrap())
159159
}
160160

161161
/// Returns whether this provenance is immutable.

Diff for: compiler/rustc_middle/src/ty/consts/int.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ impl<D: Decoder> Decodable<D> for ScalarInt {
161161
let mut data = [0u8; 16];
162162
let size = d.read_u8();
163163
data[..size as usize].copy_from_slice(d.read_raw_bytes(size as usize));
164-
ScalarInt { data: u128::from_le_bytes(data), size: NonZero::<u8>::new(size).unwrap() }
164+
ScalarInt { data: u128::from_le_bytes(data), size: NonZero::new(size).unwrap() }
165165
}
166166
}
167167

168168
impl ScalarInt {
169-
pub const TRUE: ScalarInt = ScalarInt { data: 1_u128, size: NonZero::<u8>::new(1).unwrap() };
169+
pub const TRUE: ScalarInt = ScalarInt { data: 1_u128, size: NonZero::new(1).unwrap() };
170170

171-
pub const FALSE: ScalarInt = ScalarInt { data: 0_u128, size: NonZero::<u8>::new(1).unwrap() };
171+
pub const FALSE: ScalarInt = ScalarInt { data: 0_u128, size: NonZero::new(1).unwrap() };
172172

173173
#[inline]
174174
pub fn size(self) -> Size {
@@ -196,7 +196,7 @@ impl ScalarInt {
196196

197197
#[inline]
198198
pub fn null(size: Size) -> Self {
199-
Self { data: 0, size: NonZero::<u8>::new(size.bytes() as u8).unwrap() }
199+
Self { data: 0, size: NonZero::new(size.bytes() as u8).unwrap() }
200200
}
201201

202202
#[inline]
@@ -208,7 +208,7 @@ impl ScalarInt {
208208
pub fn try_from_uint(i: impl Into<u128>, size: Size) -> Option<Self> {
209209
let data = i.into();
210210
if size.truncate(data) == data {
211-
Some(Self { data, size: NonZero::<u8>::new(size.bytes() as u8).unwrap() })
211+
Some(Self { data, size: NonZero::new(size.bytes() as u8).unwrap() })
212212
} else {
213213
None
214214
}
@@ -220,7 +220,7 @@ impl ScalarInt {
220220
// `into` performed sign extension, we have to truncate
221221
let truncated = size.truncate(i as u128);
222222
if size.sign_extend(truncated) as i128 == i {
223-
Some(Self { data: truncated, size: NonZero::<u8>::new(size.bytes() as u8).unwrap() })
223+
Some(Self { data: truncated, size: NonZero::new(size.bytes() as u8).unwrap() })
224224
} else {
225225
None
226226
}
@@ -388,7 +388,7 @@ macro_rules! from {
388388
fn from(u: $ty) -> Self {
389389
Self {
390390
data: u128::from(u),
391-
size: NonZero::<u8>::new(std::mem::size_of::<$ty>() as u8).unwrap(),
391+
size: NonZero::new(std::mem::size_of::<$ty>() as u8).unwrap(),
392392
}
393393
}
394394
}
@@ -427,10 +427,7 @@ impl TryFrom<ScalarInt> for bool {
427427
impl From<char> for ScalarInt {
428428
#[inline]
429429
fn from(c: char) -> Self {
430-
Self {
431-
data: c as u128,
432-
size: NonZero::<u8>::new(std::mem::size_of::<char>() as u8).unwrap(),
433-
}
430+
Self { data: c as u128, size: NonZero::new(std::mem::size_of::<char>() as u8).unwrap() }
434431
}
435432
}
436433

@@ -457,7 +454,7 @@ impl From<Single> for ScalarInt {
457454
#[inline]
458455
fn from(f: Single) -> Self {
459456
// We trust apfloat to give us properly truncated data.
460-
Self { data: f.to_bits(), size: NonZero::<u8>::new((Single::BITS / 8) as u8).unwrap() }
457+
Self { data: f.to_bits(), size: NonZero::new((Single::BITS / 8) as u8).unwrap() }
461458
}
462459
}
463460

@@ -473,7 +470,7 @@ impl From<Double> for ScalarInt {
473470
#[inline]
474471
fn from(f: Double) -> Self {
475472
// We trust apfloat to give us properly truncated data.
476-
Self { data: f.to_bits(), size: NonZero::<u8>::new((Double::BITS / 8) as u8).unwrap() }
473+
Self { data: f.to_bits(), size: NonZero::new((Double::BITS / 8) as u8).unwrap() }
477474
}
478475
}
479476

Diff for: compiler/rustc_middle/src/ty/generic_args.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ impl<'tcx> From<ty::Term<'tcx>> for GenericArg<'tcx> {
143143
impl<'tcx> GenericArg<'tcx> {
144144
#[inline]
145145
pub fn unpack(self) -> GenericArgKind<'tcx> {
146-
let ptr = unsafe {
147-
self.ptr.map_addr(|addr| NonZero::<usize>::new_unchecked(addr.get() & !TAG_MASK))
148-
};
146+
let ptr =
147+
unsafe { self.ptr.map_addr(|addr| NonZero::new_unchecked(addr.get() & !TAG_MASK)) };
149148
// SAFETY: use of `Interned::new_unchecked` here is ok because these
150149
// pointers were originally created from `Interned` types in `pack()`,
151150
// and this is just going in the other direction.

Diff for: compiler/rustc_middle/src/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ where
761761
};
762762
tcx.mk_layout(LayoutS {
763763
variants: Variants::Single { index: variant_index },
764-
fields: match NonZero::<usize>::new(fields) {
764+
fields: match NonZero::new(fields) {
765765
Some(fields) => FieldsShape::Union(fields),
766766
None => FieldsShape::Arbitrary { offsets: IndexVec::new(), memory_index: IndexVec::new() },
767767
},

Diff for: compiler/rustc_middle/src/ty/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,8 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for Term<'tcx> {
617617
impl<'tcx> Term<'tcx> {
618618
#[inline]
619619
pub fn unpack(self) -> TermKind<'tcx> {
620-
let ptr = unsafe {
621-
self.ptr.map_addr(|addr| NonZero::<usize>::new_unchecked(addr.get() & !TAG_MASK))
622-
};
620+
let ptr =
621+
unsafe { self.ptr.map_addr(|addr| NonZero::new_unchecked(addr.get() & !TAG_MASK)) };
623622
// SAFETY: use of `Interned::new_unchecked` here is ok because these
624623
// pointers were originally created from `Interned` types in `pack()`,
625624
// and this is just going in the other direction.

Diff for: compiler/rustc_passes/src/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
645645
let stability = Stability {
646646
level: attr::StabilityLevel::Unstable {
647647
reason: UnstableReason::Default,
648-
issue: NonZero::<u32>::new(27812),
648+
issue: NonZero::new(27812),
649649
is_soft: false,
650650
implied_by: None,
651651
},

Diff for: compiler/rustc_query_impl/src/plumbing.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ impl QueryContext for QueryCtxt<'_> {
6868
#[inline]
6969
fn next_job_id(self) -> QueryJobId {
7070
QueryJobId(
71-
NonZero::<u64>::new(
72-
self.query_system.jobs.fetch_add(1, std::sync::atomic::Ordering::Relaxed),
73-
)
74-
.unwrap(),
71+
NonZero::new(self.query_system.jobs.fetch_add(1, std::sync::atomic::Ordering::Relaxed))
72+
.unwrap(),
7573
)
7674
}
7775

Diff for: compiler/rustc_serialize/src/serialize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<S: Encoder> Encodable<S> for NonZero<u32> {
225225

226226
impl<D: Decoder> Decodable<D> for NonZero<u32> {
227227
fn decode(d: &mut D) -> Self {
228-
NonZero::<u32>::new(d.read_u32()).unwrap()
228+
NonZero::new(d.read_u32()).unwrap()
229229
}
230230
}
231231

Diff for: compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ mod parse {
10071007
}
10081008
},
10091009
None => {
1010-
*slot = NonZero::<usize>::new(1);
1010+
*slot = NonZero::new(1);
10111011
true
10121012
}
10131013
}

Diff for: library/alloc/src/collections/binary_heap/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl<T: Ord, A: Allocator> DerefMut for PeekMut<'_, T, A> {
350350
// the standard library as "leak amplification".
351351
unsafe {
352352
// SAFETY: len > 1 so len != 0.
353-
self.original_len = Some(NonZero::<usize>::new_unchecked(len));
353+
self.original_len = Some(NonZero::new_unchecked(len));
354354
// SAFETY: len > 1 so all this does for now is leak elements,
355355
// which is safe.
356356
self.heap.data.set_len(1);
@@ -1576,8 +1576,8 @@ unsafe impl<T, A: Allocator> SourceIter for IntoIter<T, A> {
15761576
#[unstable(issue = "none", feature = "inplace_iteration")]
15771577
#[doc(hidden)]
15781578
unsafe impl<I, A: Allocator> InPlaceIterable for IntoIter<I, A> {
1579-
const EXPAND_BY: Option<NonZero<usize>> = NonZero::<usize>::new(1);
1580-
const MERGE_BY: Option<NonZero<usize>> = NonZero::<usize>::new(1);
1579+
const EXPAND_BY: Option<NonZero<usize>> = NonZero::new(1);
1580+
const MERGE_BY: Option<NonZero<usize>> = NonZero::new(1);
15811581
}
15821582

15831583
unsafe impl<I> AsVecIntoIter for IntoIter<I> {

Diff for: library/alloc/src/collections/vec_deque/into_iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
6363
self.inner.drain(..n);
6464
0
6565
};
66-
NonZero::<usize>::new(rem).map_or(Ok(()), Err)
66+
NonZero::new(rem).map_or(Ok(()), Err)
6767
}
6868

6969
#[inline]
@@ -192,7 +192,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
192192
self.inner.truncate(len - n);
193193
0
194194
};
195-
NonZero::<usize>::new(rem).map_or(Ok(()), Err)
195+
NonZero::new(rem).map_or(Ok(()), Err)
196196
}
197197

198198
fn try_rfold<B, F, R>(&mut self, mut init: B, mut f: F) -> R

Diff for: library/alloc/src/vec/into_iter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
248248
unsafe {
249249
ptr::drop_in_place(to_drop);
250250
}
251-
NonZero::<usize>::new(n - step_size).map_or(Ok(()), Err)
251+
NonZero::new(n - step_size).map_or(Ok(()), Err)
252252
}
253253

254254
#[inline]
@@ -350,7 +350,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
350350
unsafe {
351351
ptr::drop_in_place(to_drop);
352352
}
353-
NonZero::<usize>::new(n - step_size).map_or(Ok(()), Err)
353+
NonZero::new(n - step_size).map_or(Ok(()), Err)
354354
}
355355
}
356356

@@ -457,8 +457,8 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for IntoIter<T, A> {
457457
#[unstable(issue = "none", feature = "inplace_iteration")]
458458
#[doc(hidden)]
459459
unsafe impl<T, A: Allocator> InPlaceIterable for IntoIter<T, A> {
460-
const EXPAND_BY: Option<NonZero<usize>> = NonZero::<usize>::new(1);
461-
const MERGE_BY: Option<NonZero<usize>> = NonZero::<usize>::new(1);
460+
const EXPAND_BY: Option<NonZero<usize>> = NonZero::new(1);
461+
const MERGE_BY: Option<NonZero<usize>> = NonZero::new(1);
462462
}
463463

464464
#[unstable(issue = "none", feature = "inplace_iteration")]

0 commit comments

Comments
 (0)