Skip to content

Commit 926ab97

Browse files
committed
Replace NonZero::<_>::new with NonZero::new.
1 parent 7870dc4 commit 926ab97

File tree

48 files changed

+130
-161
lines changed

Some content is hidden

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

48 files changed

+130
-161
lines changed

alloc/src/collections/binary_heap/mod.rs

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

alloc/src/collections/vec_deque/into_iter.rs

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

alloc/src/vec/into_iter.rs

Lines changed: 4 additions & 4 deletions
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")]

alloc/tests/vec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,9 +1089,9 @@ fn test_into_iter_advance_by() {
10891089
assert_eq!(i.advance_back_by(1), Ok(()));
10901090
assert_eq!(i.as_slice(), [2, 3, 4]);
10911091

1092-
assert_eq!(i.advance_back_by(usize::MAX), Err(NonZero::<usize>::new(usize::MAX - 3).unwrap()));
1092+
assert_eq!(i.advance_back_by(usize::MAX), Err(NonZero::new(usize::MAX - 3).unwrap()));
10931093

1094-
assert_eq!(i.advance_by(usize::MAX), Err(NonZero::<usize>::new(usize::MAX).unwrap()));
1094+
assert_eq!(i.advance_by(usize::MAX), Err(NonZero::new(usize::MAX).unwrap()));
10951095

10961096
assert_eq!(i.advance_by(0), Ok(()));
10971097
assert_eq!(i.advance_back_by(0), Ok(()));
@@ -1192,7 +1192,7 @@ fn test_from_iter_specialization_with_iterator_adapters() {
11921192
.map(|(a, b)| a + b)
11931193
.map_while(Option::Some)
11941194
.skip(1)
1195-
.map(|e| if e != usize::MAX { Ok(NonZero::<usize>::new(e)) } else { Err(()) });
1195+
.map(|e| if e != usize::MAX { Ok(NonZero::new(e)) } else { Err(()) });
11961196
assert_in_place_trait(&iter);
11971197
let sink = iter.collect::<Result<Vec<_>, _>>().unwrap();
11981198
let sinkptr = sink.as_ptr();

alloc/tests/vec_deque.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,9 @@ fn test_into_iter() {
445445
assert_eq!(it.next_back(), Some(3));
446446

447447
let mut it = VecDeque::from(vec![1, 2, 3, 4, 5]).into_iter();
448-
assert_eq!(it.advance_by(10), Err(NonZero::<usize>::new(5).unwrap()));
448+
assert_eq!(it.advance_by(10), Err(NonZero::new(5).unwrap()));
449449
let mut it = VecDeque::from(vec![1, 2, 3, 4, 5]).into_iter();
450-
assert_eq!(it.advance_back_by(10), Err(NonZero::<usize>::new(5).unwrap()));
450+
assert_eq!(it.advance_back_by(10), Err(NonZero::new(5).unwrap()));
451451
}
452452
}
453453

core/src/array/iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> {
292292
ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(slice));
293293
}
294294

295-
NonZero::<usize>::new(remaining).map_or(Ok(()), Err)
295+
NonZero::new(remaining).map_or(Ok(()), Err)
296296
}
297297

298298
#[inline]
@@ -347,7 +347,7 @@ impl<T, const N: usize> DoubleEndedIterator for IntoIter<T, N> {
347347
ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(slice));
348348
}
349349

350-
NonZero::<usize>::new(remaining).map_or(Ok(()), Err)
350+
NonZero::new(remaining).map_or(Ok(()), Err)
351351
}
352352
}
353353

core/src/iter/adapters/array_chunks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ where
255255
unsafe impl<I: InPlaceIterable + Iterator, const N: usize> InPlaceIterable for ArrayChunks<I, N> {
256256
const EXPAND_BY: Option<NonZero<usize>> = I::EXPAND_BY;
257257
const MERGE_BY: Option<NonZero<usize>> = const {
258-
match (I::MERGE_BY, NonZero::<usize>::new(N)) {
258+
match (I::MERGE_BY, NonZero::new(N)) {
259259
(Some(m), Some(n)) => m.checked_mul(n),
260260
_ => None,
261261
}

core/src/iter/adapters/chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ where
110110
// we don't fuse the second iterator
111111
}
112112

113-
NonZero::<usize>::new(n).map_or(Ok(()), Err)
113+
NonZero::new(n).map_or(Ok(()), Err)
114114
}
115115

116116
#[inline]
@@ -196,7 +196,7 @@ where
196196
// we don't fuse the second iterator
197197
}
198198

199-
NonZero::<usize>::new(n).map_or(Ok(()), Err)
199+
NonZero::new(n).map_or(Ok(()), Err)
200200
}
201201

202202
#[inline]

core/src/iter/adapters/cycle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ where
9797
};
9898
}
9999

100-
NonZero::<usize>::new(n).map_or(Ok(()), Err)
100+
NonZero::new(n).map_or(Ok(()), Err)
101101
}
102102

103103
// No `fold` override, because `fold` doesn't make much sense for `Cycle`,

core/src/iter/adapters/flatten.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ where
200200
#[rustc_specialization_trait]
201201
#[unstable(issue = "none", feature = "inplace_iteration")]
202202
unsafe trait BoundedSize {
203-
const UPPER_BOUND: Option<NonZero<usize>> = NonZero::<usize>::new(1);
203+
const UPPER_BOUND: Option<NonZero<usize>> = NonZero::new(1);
204204
}
205205

206206
#[unstable(issue = "none", feature = "inplace_iteration")]
@@ -217,11 +217,11 @@ unsafe impl<T> BoundedSize for Once<T> {}
217217
unsafe impl<T> BoundedSize for OnceWith<T> {}
218218
#[unstable(issue = "none", feature = "inplace_iteration")]
219219
unsafe impl<T, const N: usize> BoundedSize for [T; N] {
220-
const UPPER_BOUND: Option<NonZero<usize>> = NonZero::<usize>::new(N);
220+
const UPPER_BOUND: Option<NonZero<usize>> = NonZero::new(N);
221221
}
222222
#[unstable(issue = "none", feature = "inplace_iteration")]
223223
unsafe impl<T, const N: usize> BoundedSize for array::IntoIter<T, N> {
224-
const UPPER_BOUND: Option<NonZero<usize>> = NonZero::<usize>::new(N);
224+
const UPPER_BOUND: Option<NonZero<usize>> = NonZero::new(N);
225225
}
226226
#[unstable(issue = "none", feature = "inplace_iteration")]
227227
unsafe impl<I: BoundedSize, P> BoundedSize for Filter<I, P> {
@@ -680,9 +680,7 @@ where
680680
}
681681

682682
match self.iter_try_fold(n, advance) {
683-
ControlFlow::Continue(remaining) => {
684-
NonZero::<usize>::new(remaining).map_or(Ok(()), Err)
685-
}
683+
ControlFlow::Continue(remaining) => NonZero::new(remaining).map_or(Ok(()), Err),
686684
_ => Ok(()),
687685
}
688686
}
@@ -772,9 +770,7 @@ where
772770
}
773771

774772
match self.iter_try_rfold(n, advance) {
775-
ControlFlow::Continue(remaining) => {
776-
NonZero::<usize>::new(remaining).map_or(Ok(()), Err)
777-
}
773+
ControlFlow::Continue(remaining) => NonZero::new(remaining).map_or(Ok(()), Err),
778774
_ => Ok(()),
779775
}
780776
}

0 commit comments

Comments
 (0)