Skip to content

Commit

Permalink
Rollup merge of rust-lang#124230 - reitermarkus:generic-nonzero-stabl…
Browse files Browse the repository at this point in the history
…e, r=dtolnay

Stabilize generic `NonZero`.

Tracking issue: rust-lang#120257

r? `@dtolnay`
  • Loading branch information
GuillaumeGomez authored Apr 22, 2024
2 parents 17c2879 + 33e68aa commit 6a326d8
Show file tree
Hide file tree
Showing 67 changed files with 69 additions and 111 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_attr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#![allow(internal_features)]
#![feature(rustdoc_internals)]
#![doc(rust_logo)]
#![feature(generic_nonzero)]
#![feature(let_chains)]

#[macro_use]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_const_eval/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Rust MIR: a lowered representation of Rust.
#![feature(assert_matches)]
#![feature(box_patterns)]
#![feature(decl_macro)]
#![feature(generic_nonzero)]
#![feature(let_chains)]
#![feature(slice_ptr_get)]
#![feature(strict_provenance)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#![feature(cfg_match)]
#![feature(core_intrinsics)]
#![feature(extend_one)]
#![feature(generic_nonzero)]
#![feature(hash_raw_entry)]
#![feature(hasher_prefixfree_extras)]
#![feature(lazy_cell)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#![feature(box_patterns)]
#![feature(error_reporter)]
#![feature(extract_if)]
#![feature(generic_nonzero)]
#![feature(let_chains)]
#![feature(negative_impls)]
#![feature(never_type)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_feature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//! symbol to the `accepted` or `removed` modules respectively.
#![allow(internal_features)]
#![feature(generic_nonzero)]
#![feature(rustdoc_internals)]
#![doc(rust_logo)]
#![feature(lazy_cell)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ This API is completely unstable and subject to change.
#![feature(rustdoc_internals)]
#![allow(internal_features)]
#![feature(control_flow_enum)]
#![feature(generic_nonzero)]
#![feature(if_let_guard)]
#![feature(is_sorted)]
#![feature(iter_intersperse)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(decl_macro)]
#![feature(generic_nonzero)]
#![feature(lazy_cell)]
#![feature(let_chains)]
#![feature(thread_spawn_unchecked)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#![feature(box_patterns)]
#![feature(control_flow_enum)]
#![feature(extract_if)]
#![feature(generic_nonzero)]
#![feature(if_let_guard)]
#![feature(iter_order_by)]
#![feature(let_chains)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#![feature(error_iter)]
#![feature(extract_if)]
#![feature(coroutines)]
#![feature(generic_nonzero)]
#![feature(iter_from_coroutine)]
#![feature(let_chains)]
#![feature(if_let_guard)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#![feature(const_type_name)]
#![feature(discriminant_kind)]
#![feature(coroutines)]
#![feature(generic_nonzero)]
#![feature(if_let_guard)]
#![feature(inline_const)]
#![feature(iter_from_coroutine)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_passes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#![doc(rust_logo)]
#![feature(rustdoc_internals)]
#![allow(internal_features)]
#![feature(generic_nonzero)]
#![feature(let_chains)]
#![feature(map_try_insert)]
#![feature(try_blocks)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(rustdoc_internals)]
#![feature(generic_nonzero)]
#![feature(min_specialization)]
#![feature(rustc_attrs)]
#![allow(rustc::potential_query_instability, unused_parens)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_query_system/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(assert_matches)]
#![feature(core_intrinsics)]
#![feature(generic_nonzero)]
#![feature(hash_raw_entry)]
#![feature(min_specialization)]
#![feature(let_chains)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_serialize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![feature(const_option)]
#![feature(core_intrinsics)]
#![feature(generic_nonzero)]
#![feature(inline_const)]
#![feature(min_specialization)]
#![feature(never_type)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_session/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(generic_nonzero)]
#![feature(let_chains)]
#![feature(lazy_cell)]
#![feature(option_get_or_insert_default)]
Expand Down
1 change: 0 additions & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
#![feature(extend_one)]
#![feature(fmt_internals)]
#![feature(fn_traits)]
#![feature(generic_nonzero)]
#![feature(hasher_prefixfree_extras)]
#![feature(hint_assert_unchecked)]
#![feature(inline_const)]
Expand Down
1 change: 0 additions & 1 deletion library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#![feature(core_intrinsics)]
#![feature(extract_if)]
#![feature(exact_size_is_empty)]
#![feature(generic_nonzero)]
#![feature(linked_list_cursors)]
#![feature(map_try_insert)]
#![feature(new_uninit)]
Expand Down
5 changes: 4 additions & 1 deletion library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ impl<T, const N: usize> [T; N] {
/// # Examples
///
/// ```
/// #![feature(array_try_map, generic_nonzero)]
/// #![feature(array_try_map)]
///
/// let a = ["1", "2", "3"];
/// let b = a.try_map(|v| v.parse::<u32>()).unwrap().map(|v| v + 1);
/// assert_eq!(b, [2, 3, 4]);
Expand All @@ -522,8 +523,10 @@ impl<T, const N: usize> [T; N] {
/// assert!(b.is_err());
///
/// use std::num::NonZero;
///
/// let z = [1, 2, 0, 3, 4];
/// assert_eq!(z.try_map(NonZero::new), None);
///
/// let a = [1, 2, 3];
/// let b = a.try_map(NonZero::new);
/// let c = b.map(|x| x.map(NonZero::get));
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/iter/traits/double_ended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ pub trait DoubleEndedIterator: Iterator {
/// Basic usage:
///
/// ```
/// #![feature(generic_nonzero, iter_advance_by)]
/// #![feature(iter_advance_by)]
///
/// use std::num::NonZero;
///
/// let a = [3, 4, 5, 6];
Expand Down
6 changes: 4 additions & 2 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ pub trait Iterator {
/// # Examples
///
/// ```
/// #![feature(generic_nonzero, iter_advance_by)]
/// #![feature(iter_advance_by)]
///
/// use std::num::NonZero;
///
/// let a = [1, 2, 3, 4];
Expand Down Expand Up @@ -2939,7 +2940,8 @@ pub trait Iterator {
/// This also supports other types which implement [`Try`], not just [`Result`].
///
/// ```
/// #![feature(generic_nonzero, try_find)]
/// #![feature(try_find)]
///
/// use std::num::NonZero;
///
/// let a = [3, 5, 7, 4, 9, 0, 11u32];
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ pub use error::ParseIntError;
)]
pub use nonzero::ZeroablePrimitive;

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

#[stable(feature = "nonzero", since = "1.28.0")]
pub use nonzero::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};

#[stable(feature = "signed_nonzero", since = "1.34.0")]
pub use nonzero::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize};

#[stable(feature = "nonzero", since = "1.28.0")]
pub use nonzero::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};

#[stable(feature = "try_from", since = "1.34.0")]
pub use error::TryFromIntError;

Expand Down
10 changes: 5 additions & 5 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ impl_zeroable_primitive!(
/// For example, `Option<NonZero<u32>>` is the same size as `u32`:
///
/// ```
/// #![feature(generic_nonzero)]
/// use core::mem::size_of;
/// use core::{mem::size_of, num::NonZero};
///
/// assert_eq!(size_of::<Option<core::num::NonZero<u32>>>(), size_of::<u32>());
/// assert_eq!(size_of::<Option<NonZero<u32>>>(), size_of::<u32>());
/// ```
#[unstable(feature = "generic_nonzero", issue = "120257")]
#[stable(feature = "generic_nonzero", since = "CURRENT_RUSTC_VERSION")]
#[repr(transparent)]
#[rustc_nonnull_optimization_guaranteed]
#[rustc_diagnostic_item = "NonZero"]
Expand Down Expand Up @@ -562,7 +561,8 @@ macro_rules! nonzero_integer {
/// Basic usage:
///
/// ```
/// #![feature(generic_nonzero, non_zero_count_ones)]
/// #![feature(non_zero_count_ones)]
///
/// # fn main() { test().unwrap(); }
/// # fn test() -> Option<()> {
/// # use std::num::*;
Expand Down
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#![feature(float_minimum_maximum)]
#![feature(future_join)]
#![feature(generic_assert_internals)]
#![feature(generic_nonzero)]
#![feature(array_try_from_fn)]
#![feature(hasher_prefixfree_extras)]
#![feature(hashmap_internals)]
Expand Down
1 change: 0 additions & 1 deletion library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#![feature(staged_api)]
#![feature(allow_internal_unstable)]
#![feature(decl_macro)]
#![feature(generic_nonzero)]
#![feature(maybe_uninit_write_slice)]
#![feature(negative_impls)]
#![feature(new_uninit)]
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@
#![feature(float_minimum_maximum)]
#![feature(float_next_up_down)]
#![feature(fmt_internals)]
#![feature(generic_nonzero)]
#![feature(hasher_prefixfree_extras)]
#![feature(hashmap_internals)]
#![feature(hint_assert_unchecked)]
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ pub use core::num::{FpCategory, ParseFloatError, ParseIntError, TryFromIntError}
)]
pub use core::num::ZeroablePrimitive;

#[unstable(feature = "generic_nonzero", issue = "120257")]
#[stable(feature = "generic_nonzero", since = "CURRENT_RUSTC_VERSION")]
pub use core::num::NonZero;

#[stable(feature = "signed_nonzero", since = "1.34.0")]
pub use core::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize};

#[stable(feature = "nonzero", since = "1.28.0")]
pub use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};

Expand Down
3 changes: 2 additions & 1 deletion library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,8 @@ impl ExitStatusError {
/// # Examples
///
/// ```
/// #![feature(exit_status_error, generic_nonzero)]
/// #![feature(exit_status_error)]
///
/// # if cfg!(unix) {
/// use std::num::NonZero;
/// use std::process::Command;
Expand Down
1 change: 0 additions & 1 deletion library/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#![unstable(feature = "test", issue = "50297")]
#![doc(test(attr(deny(warnings))))]
#![doc(rust_logo)]
#![feature(generic_nonzero)]
#![feature(rustdoc_internals)]
#![feature(internal_output_capture)]
#![feature(staged_api)]
Expand Down
1 change: 0 additions & 1 deletion src/tools/miri/src/bin/miri.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(generic_nonzero)]
#![feature(rustc_private, stmt_expr_attributes)]
#![allow(
clippy::manual_range_contains,
Expand Down
1 change: 0 additions & 1 deletion src/tools/miri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![feature(cell_update)]
#![feature(const_option)]
#![feature(float_gamma)]
#![feature(generic_nonzero)]
#![feature(map_try_insert)]
#![feature(never_type)]
#![feature(try_blocks)]
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/array-equality.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ compile-flags: -O -Z merge-functions=disabled
//@ only-x86_64
#![crate_type = "lib"]
#![feature(generic_nonzero)]

// CHECK-LABEL: @array_eq_value
#[no_mangle]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/enum/enum-debug-niche-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_variant_part,{{.*}}size: 32,{{.*}}
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i128 4294967295{{[,)].*}}
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i128 0{{[,)].*}}
#![feature(generic_nonzero, never_type)]
#![feature(never_type)]

#[derive(Copy, Clone)]
pub struct Entity {
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/function-arguments.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ compile-flags: -O -C no-prepopulate-passes
#![crate_type = "lib"]
#![feature(dyn_star)]
#![feature(generic_nonzero)]
#![feature(allocator_api)]

use std::mem::MaybeUninit;
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/intrinsics/transmute-niched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//@ [DBG] compile-flags: -C opt-level=0 -C no-prepopulate-passes
//@ only-64bit (so I don't need to worry about usize)
#![crate_type = "lib"]
#![feature(generic_nonzero)]

use std::mem::transmute;
use std::num::NonZero;
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/issues/issue-119422.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//@ compile-flags: -O --edition=2021 -Zmerge-functions=disabled
//@ only-64bit (because the LLVM type of i64 for usize shows up)
#![crate_type = "lib"]
#![feature(generic_nonzero)]

use core::ptr::NonNull;
use core::num::NonZero;
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/loads.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0 -O

#![crate_type = "lib"]
#![feature(generic_nonzero)]

use std::mem::MaybeUninit;
use std::num::NonZero;
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/option-as-slice.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ compile-flags: -O -Z randomize-layout=no
//@ only-x86_64
#![crate_type = "lib"]
#![feature(generic_nonzero)]

extern crate core;

Expand Down
1 change: 0 additions & 1 deletion tests/codegen/option-niche-eq.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ compile-flags: -O -Zmerge-functions=disabled
//@ min-llvm-version: 18
#![crate_type = "lib"]
#![feature(generic_nonzero)]

extern crate core;
use core::cmp::Ordering;
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/slice-ref-equality.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ compile-flags: -O -Zmerge-functions=disabled
#![crate_type = "lib"]
#![feature(generic_nonzero)]

use std::num::NonZero;

Expand Down
1 change: 0 additions & 1 deletion tests/codegen/transmute-optimized.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ compile-flags: -O -Z merge-functions=disabled
#![crate_type = "lib"]
#![feature(generic_nonzero)]

// This tests that LLVM can optimize based on the niches in the source or
// destination types for transmutes.
Expand Down
1 change: 0 additions & 1 deletion tests/debuginfo/msvc-pretty-enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
// cdb-command: dx -r2 arbitrary_discr2,d
// cdb-check: arbitrary_discr2,d : Def [Type: enum2$<msvc_pretty_enums::ArbitraryDiscr>]
// cdb-check: [+0x[...]] __0 : 5678 [Type: unsigned int]
#![feature(generic_nonzero)]
#![feature(rustc_attrs)]
#![feature(repr128)]
#![feature(arbitrary_enum_discriminant)]
Expand Down
1 change: 0 additions & 1 deletion tests/debuginfo/numeric-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@

// lldb-command:v nz_usize
// lldb-check:[...] 122 { __0 = { 0 = 122 } }
#![feature(generic_nonzero)]

use std::num::*;
use std::sync::atomic::*;
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/instsimplify/combine_transmutes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![crate_type = "lib"]
#![feature(core_intrinsics)]
#![feature(custom_mir)]
#![feature(generic_nonzero)]

use std::intrinsics::mir::*;
use std::mem::{MaybeUninit, ManuallyDrop, transmute};
Expand Down
Loading

0 comments on commit 6a326d8

Please sign in to comment.