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

compiler/rustc_data_structures/src/tagged_ptr/copy.rs

Lines changed: 2 additions & 3 deletions
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

compiler/rustc_feature/src/lib.rs

Lines changed: 1 addition & 1 deletion
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

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 1 deletion
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);

compiler/rustc_interface/src/util.rs

Lines changed: 1 addition & 1 deletion
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, || {

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 4 additions & 6 deletions
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 {

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 3 additions & 3 deletions
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);

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 1 deletion
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

compiler/rustc_metadata/src/rmeta/table.rs

Lines changed: 3 additions & 3 deletions
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
)

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 1 addition & 1 deletion
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
}

compiler/rustc_middle/src/mir/interpret/mod.rs

Lines changed: 1 addition & 1 deletion
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 {

0 commit comments

Comments
 (0)