Skip to content

Commit fca5bab

Browse files
committed
Stabilize generic NonZero.
1 parent aa31bad commit fca5bab

File tree

63 files changed

+216
-255
lines changed

Some content is hidden

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

63 files changed

+216
-255
lines changed

compiler/rustc_ast/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,7 @@ pub enum TyKind {
21582158
MacCall(P<MacCall>),
21592159
/// Placeholder for a `va_list`.
21602160
CVarArgs,
2161-
/// Pattern types like `pattern_type!(u32 is 1..=)`, which is the same as `NonZeroU32`,
2161+
/// Pattern types like `pattern_type!(u32 is 1..=)`, which is the same as `NonZero<u32>`,
21622162
/// just as part of the type system.
21632163
Pat(P<Ty>, P<Pat>),
21642164
/// Sometimes we need a dummy value when no error has occurred.

compiler/rustc_attr/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#![allow(internal_features)]
88
#![feature(rustdoc_internals)]
99
#![doc(rust_logo)]
10-
#![feature(generic_nonzero)]
1110
#![feature(let_chains)]
1211

1312
#[macro_use]

compiler/rustc_const_eval/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Rust MIR: a lowered representation of Rust.
1111
#![feature(assert_matches)]
1212
#![feature(box_patterns)]
1313
#![feature(decl_macro)]
14-
#![feature(generic_nonzero)]
1514
#![feature(let_chains)]
1615
#![feature(slice_ptr_get)]
1716
#![feature(strict_provenance)]

compiler/rustc_data_structures/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#![feature(cfg_match)]
2121
#![feature(core_intrinsics)]
2222
#![feature(extend_one)]
23-
#![feature(generic_nonzero)]
2423
#![feature(hash_raw_entry)]
2524
#![feature(hasher_prefixfree_extras)]
2625
#![feature(lazy_cell)]

compiler/rustc_errors/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![feature(box_patterns)]
1616
#![feature(error_reporter)]
1717
#![feature(extract_if)]
18-
#![feature(generic_nonzero)]
1918
#![feature(let_chains)]
2019
#![feature(negative_impls)]
2120
#![feature(never_type)]

compiler/rustc_feature/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//! symbol to the `accepted` or `removed` modules respectively.
1313
1414
#![allow(internal_features)]
15-
#![feature(generic_nonzero)]
1615
#![feature(rustdoc_internals)]
1716
#![doc(rust_logo)]
1817
#![feature(lazy_cell)]

compiler/rustc_hir_analysis/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ This API is completely unstable and subject to change.
6363
#![feature(rustdoc_internals)]
6464
#![allow(internal_features)]
6565
#![feature(control_flow_enum)]
66-
#![feature(generic_nonzero)]
6766
#![feature(if_let_guard)]
6867
#![feature(is_sorted)]
6968
#![feature(iter_intersperse)]

compiler/rustc_interface/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(decl_macro)]
2-
#![feature(generic_nonzero)]
32
#![feature(lazy_cell)]
43
#![feature(let_chains)]
54
#![feature(thread_spawn_unchecked)]

compiler/rustc_lint/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#![feature(box_patterns)]
3333
#![feature(control_flow_enum)]
3434
#![feature(extract_if)]
35-
#![feature(generic_nonzero)]
3635
#![feature(if_let_guard)]
3736
#![feature(iter_order_by)]
3837
#![feature(let_chains)]

compiler/rustc_metadata/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#![feature(error_iter)]
77
#![feature(extract_if)]
88
#![feature(coroutines)]
9-
#![feature(generic_nonzero)]
109
#![feature(iter_from_coroutine)]
1110
#![feature(let_chains)]
1211
#![feature(if_let_guard)]

compiler/rustc_middle/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#![feature(const_type_name)]
3636
#![feature(discriminant_kind)]
3737
#![feature(coroutines)]
38-
#![feature(generic_nonzero)]
3938
#![feature(if_let_guard)]
4039
#![feature(inline_const)]
4140
#![feature(iter_from_coroutine)]

compiler/rustc_passes/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#![doc(rust_logo)]
99
#![feature(rustdoc_internals)]
1010
#![allow(internal_features)]
11-
#![feature(generic_nonzero)]
1211
#![feature(let_chains)]
1312
#![feature(map_try_insert)]
1413
#![feature(try_blocks)]

compiler/rustc_query_impl/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
44
#![doc(rust_logo)]
55
#![feature(rustdoc_internals)]
6-
#![feature(generic_nonzero)]
76
#![feature(min_specialization)]
87
#![feature(rustc_attrs)]
98
#![allow(rustc::potential_query_instability, unused_parens)]

compiler/rustc_query_system/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![feature(assert_matches)]
22
#![feature(core_intrinsics)]
3-
#![feature(generic_nonzero)]
43
#![feature(hash_raw_entry)]
54
#![feature(min_specialization)]
65
#![feature(let_chains)]

compiler/rustc_serialize/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
1212
#![feature(const_option)]
1313
#![feature(core_intrinsics)]
14-
#![feature(generic_nonzero)]
1514
#![feature(inline_const)]
1615
#![feature(min_specialization)]
1716
#![feature(never_type)]

compiler/rustc_session/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(generic_nonzero)]
21
#![feature(let_chains)]
32
#![feature(lazy_cell)]
43
#![feature(option_get_or_insert_default)]

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
#![feature(extend_one)]
127127
#![feature(fmt_internals)]
128128
#![feature(fn_traits)]
129-
#![feature(generic_nonzero)]
130129
#![feature(hasher_prefixfree_extras)]
131130
#![feature(hint_assert_unchecked)]
132131
#![feature(inline_const)]

library/alloc/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#![feature(core_intrinsics)]
1515
#![feature(extract_if)]
1616
#![feature(exact_size_is_empty)]
17-
#![feature(generic_nonzero)]
1817
#![feature(linked_list_cursors)]
1918
#![feature(map_try_insert)]
2019
#![feature(new_uninit)]

library/core/src/array/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ impl<T, const N: usize> [T; N] {
512512
/// # Examples
513513
///
514514
/// ```
515-
/// #![feature(array_try_map, generic_nonzero)]
515+
/// #![feature(array_try_map)]
516+
///
516517
/// let a = ["1", "2", "3"];
517518
/// let b = a.try_map(|v| v.parse::<u32>()).unwrap().map(|v| v + 1);
518519
/// assert_eq!(b, [2, 3, 4]);
@@ -522,8 +523,10 @@ impl<T, const N: usize> [T; N] {
522523
/// assert!(b.is_err());
523524
///
524525
/// use std::num::NonZero;
526+
///
525527
/// let z = [1, 2, 0, 3, 4];
526528
/// assert_eq!(z.try_map(NonZero::new), None);
529+
///
527530
/// let a = [1, 2, 3];
528531
/// let b = a.try_map(NonZero::new);
529532
/// let c = b.map(|x| x.map(NonZero::get));

library/core/src/iter/adapters/step_by.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
intrinsics,
33
iter::{from_fn, TrustedLen, TrustedRandomAccess},
4-
num::NonZeroUsize,
4+
num::NonZero,
55
ops::{Range, Try},
66
};
77

@@ -42,10 +42,10 @@ impl<I> StepBy<I> {
4242
/// The `step` that was originally passed to `Iterator::step_by(step)`,
4343
/// aka `self.step_minus_one + 1`.
4444
#[inline]
45-
fn original_step(&self) -> NonZeroUsize {
45+
fn original_step(&self) -> NonZero<usize> {
4646
// SAFETY: By type invariant, `step_minus_one` cannot be `MAX`, which
4747
// means the addition cannot overflow and the result cannot be zero.
48-
unsafe { NonZeroUsize::new_unchecked(intrinsics::unchecked_add(self.step_minus_one, 1)) }
48+
unsafe { NonZero::new_unchecked(intrinsics::unchecked_add(self.step_minus_one, 1)) }
4949
}
5050
}
5151

@@ -231,12 +231,12 @@ unsafe impl<I: Iterator> StepByImpl<I> for StepBy<I> {
231231
#[inline]
232232
default fn spec_size_hint(&self) -> (usize, Option<usize>) {
233233
#[inline]
234-
fn first_size(step: NonZeroUsize) -> impl Fn(usize) -> usize {
234+
fn first_size(step: NonZero<usize>) -> impl Fn(usize) -> usize {
235235
move |n| if n == 0 { 0 } else { 1 + (n - 1) / step }
236236
}
237237

238238
#[inline]
239-
fn other_size(step: NonZeroUsize) -> impl Fn(usize) -> usize {
239+
fn other_size(step: NonZero<usize>) -> impl Fn(usize) -> usize {
240240
move |n| n / step
241241
}
242242

library/core/src/iter/traits/double_ended.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ pub trait DoubleEndedIterator: Iterator {
118118
/// Basic usage:
119119
///
120120
/// ```
121-
/// #![feature(generic_nonzero, iter_advance_by)]
121+
/// #![feature(iter_advance_by)]
122+
///
122123
/// use std::num::NonZero;
123124
///
124125
/// let a = [3, 4, 5, 6];

library/core/src/iter/traits/iterator.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ pub trait Iterator {
288288
/// # Examples
289289
///
290290
/// ```
291-
/// #![feature(generic_nonzero, iter_advance_by)]
291+
/// #![feature(iter_advance_by)]
292+
///
292293
/// use std::num::NonZero;
293294
///
294295
/// let a = [1, 2, 3, 4];
@@ -2939,7 +2940,8 @@ pub trait Iterator {
29392940
/// This also supports other types which implement [`Try`], not just [`Result`].
29402941
///
29412942
/// ```
2942-
/// #![feature(generic_nonzero, try_find)]
2943+
/// #![feature(try_find)]
2944+
///
29432945
/// use std::num::NonZero;
29442946
///
29452947
/// let a = [3, 5, 7, 4, 9, 0, 11u32];

library/core/src/num/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ pub use error::ParseIntError;
6767
)]
6868
pub use nonzero::ZeroablePrimitive;
6969

70-
#[unstable(feature = "generic_nonzero", issue = "120257")]
70+
#[stable(feature = "generic_nonzero", since = "CURRENT_RUSTC_VERSION")]
7171
pub use nonzero::NonZero;
7272

73+
#[allow(deprecated_in_future)]
7374
#[stable(feature = "nonzero", since = "1.28.0")]
7475
pub use nonzero::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
7576

77+
#[allow(deprecated_in_future)]
7678
#[stable(feature = "signed_nonzero", since = "1.34.0")]
7779
pub use nonzero::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize};
7880

0 commit comments

Comments
 (0)