Skip to content

Commit 1345744

Browse files
committed
Stabilize unsigned num_midpoint feature
1 parent f6648f2 commit 1345744

File tree

9 files changed

+31
-40
lines changed

9 files changed

+31
-40
lines changed

library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@
130130
#![feature(const_make_ascii)]
131131
#![feature(const_maybe_uninit_assume_init)]
132132
#![feature(const_nonnull_new)]
133-
#![feature(const_num_midpoint)]
134133
#![feature(const_option_ext)]
135134
#![feature(const_pin)]
136135
#![feature(const_pointer_is_aligned)]

library/core/src/num/f128.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,6 @@ impl f128 {
820820
///
821821
/// ```
822822
/// #![feature(f128)]
823-
/// #![feature(num_midpoint)]
824823
/// # // Using aarch64 because `reliable_f128_math` is needed
825824
/// # #[cfg(all(target_arch = "aarch64", target_os = "linux"))] {
826825
///
@@ -830,8 +829,8 @@ impl f128 {
830829
/// ```
831830
#[inline]
832831
#[unstable(feature = "f128", issue = "116909")]
833-
// #[unstable(feature = "num_midpoint", issue = "110840")]
834-
pub fn midpoint(self, other: f128) -> f128 {
832+
#[rustc_const_unstable(feature = "f128", issue = "116909")]
833+
pub const fn midpoint(self, other: f128) -> f128 {
835834
const LO: f128 = f128::MIN_POSITIVE * 2.;
836835
const HI: f128 = f128::MAX / 2.;
837836

library/core/src/num/f16.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,6 @@ impl f16 {
806806
///
807807
/// ```
808808
/// #![feature(f16)]
809-
/// #![feature(num_midpoint)]
810809
/// # #[cfg(target_arch = "aarch64")] { // FIXME(f16_F128): rust-lang/rust#123885
811810
///
812811
/// assert_eq!(1f16.midpoint(4.0), 2.5);
@@ -815,8 +814,8 @@ impl f16 {
815814
/// ```
816815
#[inline]
817816
#[unstable(feature = "f16", issue = "116909")]
818-
// #[unstable(feature = "num_midpoint", issue = "110840")]
819-
pub fn midpoint(self, other: f16) -> f16 {
817+
#[rustc_const_unstable(feature = "f16", issue = "116909")]
818+
pub const fn midpoint(self, other: f16) -> f16 {
820819
const LO: f16 = f16::MIN_POSITIVE * 2.;
821820
const HI: f16 = f16::MAX / 2.;
822821

library/core/src/num/f32.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -989,27 +989,27 @@ impl f32 {
989989
/// # Examples
990990
///
991991
/// ```
992-
/// #![feature(num_midpoint)]
993992
/// assert_eq!(1f32.midpoint(4.0), 2.5);
994993
/// assert_eq!((-5.5f32).midpoint(8.0), 1.25);
995994
/// ```
996995
#[inline]
997-
#[unstable(feature = "num_midpoint", issue = "110840")]
998-
pub fn midpoint(self, other: f32) -> f32 {
996+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
997+
#[rustc_const_stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
998+
pub const fn midpoint(self, other: f32) -> f32 {
999999
cfg_if! {
1000+
// Allow faster implementation that have known good 64-bit float
1001+
// implementations. Falling back to the branchy code on targets that don't
1002+
// have 64-bit hardware floats or buggy implementations.
1003+
// https://github.com/rust-lang/rust/pull/121062#issuecomment-2123408114
10001004
if #[cfg(any(
10011005
target_arch = "x86_64",
10021006
target_arch = "aarch64",
1003-
all(any(target_arch="riscv32", target_arch= "riscv64"), target_feature="d"),
1004-
all(target_arch = "arm", target_feature="vfp2"),
1007+
all(any(target_arch = "riscv32", target_arch = "riscv64"), target_feature = "d"),
1008+
all(target_arch = "arm", target_feature = "vfp2"),
10051009
target_arch = "wasm32",
10061010
target_arch = "wasm64",
10071011
))] {
1008-
// whitelist the faster implementation to targets that have known good 64-bit float
1009-
// implementations. Falling back to the branchy code on targets that don't have
1010-
// 64-bit hardware floats or buggy implementations.
1011-
// see: https://github.com/rust-lang/rust/pull/121062#issuecomment-2123408114
1012-
((f64::from(self) + f64::from(other)) / 2.0) as f32
1012+
((self as f64 + other as f64) / 2.0) as f32
10131013
} else {
10141014
const LO: f32 = f32::MIN_POSITIVE * 2.;
10151015
const HI: f32 = f32::MAX / 2.;

library/core/src/num/f64.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1007,13 +1007,13 @@ impl f64 {
10071007
/// # Examples
10081008
///
10091009
/// ```
1010-
/// #![feature(num_midpoint)]
10111010
/// assert_eq!(1f64.midpoint(4.0), 2.5);
10121011
/// assert_eq!((-5.5f64).midpoint(8.0), 1.25);
10131012
/// ```
10141013
#[inline]
1015-
#[unstable(feature = "num_midpoint", issue = "110840")]
1016-
pub fn midpoint(self, other: f64) -> f64 {
1014+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
1015+
#[rustc_const_stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
1016+
pub const fn midpoint(self, other: f64) -> f64 {
10171017
const LO: f64 = f64::MIN_POSITIVE * 2.;
10181018
const HI: f64 = f64::MAX / 2.;
10191019

library/core/src/num/int_macros.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -3190,14 +3190,13 @@ macro_rules! int_impl {
31903190
/// # Examples
31913191
///
31923192
/// ```
3193-
/// #![feature(num_midpoint)]
3193+
/// #![feature(num_midpoint_signed)]
31943194
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(4), 2);")]
31953195
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(-1), -1);")]
31963196
#[doc = concat!("assert_eq!((-1", stringify!($SelfT), ").midpoint(0), -1);")]
31973197
/// ```
3198-
#[unstable(feature = "num_midpoint", issue = "110840")]
3199-
#[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")]
3200-
#[rustc_allow_const_fn_unstable(const_num_midpoint)]
3198+
#[unstable(feature = "num_midpoint_signed", issue = "110840")]
3199+
#[rustc_const_unstable(feature = "num_midpoint_signed", issue = "110840")]
32013200
#[must_use = "this returns the result of the operation, \
32023201
without modifying the original"]
32033202
#[inline]

library/core/src/num/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,18 @@ macro_rules! midpoint_impl {
109109
($SelfT:ty, unsigned) => {
110110
/// Calculates the middle point of `self` and `rhs`.
111111
///
112-
/// `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a
113-
/// sufficiently-large signed integral type. This implies that the result is
112+
/// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a
113+
/// sufficiently-large unsigned integral type. This implies that the result is
114114
/// always rounded towards negative infinity and that no overflow will ever occur.
115115
///
116116
/// # Examples
117117
///
118118
/// ```
119-
/// #![feature(num_midpoint)]
120119
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(4), 2);")]
121120
#[doc = concat!("assert_eq!(1", stringify!($SelfT), ".midpoint(4), 2);")]
122121
/// ```
123-
#[unstable(feature = "num_midpoint", issue = "110840")]
124-
#[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")]
122+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
123+
#[rustc_const_stable(feature = "const_num_midpoint", since = "CURRENT_RUSTC_VERSION")]
125124
#[must_use = "this returns the result of the operation, \
126125
without modifying the original"]
127126
#[inline]
@@ -134,19 +133,18 @@ macro_rules! midpoint_impl {
134133
($SelfT:ty, $WideT:ty, unsigned) => {
135134
/// Calculates the middle point of `self` and `rhs`.
136135
///
137-
/// `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a
138-
/// sufficiently-large signed integral type. This implies that the result is
136+
/// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a
137+
/// sufficiently-large unsigned integral type. This implies that the result is
139138
/// always rounded towards negative infinity and that no overflow will ever occur.
140139
///
141140
/// # Examples
142141
///
143142
/// ```
144-
/// #![feature(num_midpoint)]
145143
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(4), 2);")]
146144
#[doc = concat!("assert_eq!(1", stringify!($SelfT), ".midpoint(4), 2);")]
147145
/// ```
148-
#[unstable(feature = "num_midpoint", issue = "110840")]
149-
#[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")]
146+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
147+
#[rustc_const_stable(feature = "const_num_midpoint", since = "CURRENT_RUSTC_VERSION")]
150148
#[must_use = "this returns the result of the operation, \
151149
without modifying the original"]
152150
#[inline]

library/core/src/num/nonzero.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1458,8 +1458,6 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
14581458
/// # Examples
14591459
///
14601460
/// ```
1461-
/// #![feature(num_midpoint)]
1462-
///
14631461
/// # use std::num::NonZero;
14641462
/// #
14651463
/// # fn main() { test().unwrap(); }
@@ -1473,9 +1471,8 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
14731471
/// # Some(())
14741472
/// # }
14751473
/// ```
1476-
#[unstable(feature = "num_midpoint", issue = "110840")]
1477-
#[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")]
1478-
#[rustc_allow_const_fn_unstable(const_num_midpoint)]
1474+
#[stable(feature = "num_midpoint", since = "CURRENT_RUSTC_VERSION")]
1475+
#[rustc_const_stable(feature = "const_num_midpoint", since = "CURRENT_RUSTC_VERSION")]
14791476
#[must_use = "this returns the result of the operation, \
14801477
without modifying the original"]
14811478
#[inline]

library/core/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
#![feature(min_specialization)]
7373
#![feature(never_type)]
7474
#![feature(noop_waker)]
75-
#![feature(num_midpoint)]
75+
#![feature(num_midpoint_signed)]
7676
#![feature(numfmt)]
7777
#![feature(pattern)]
7878
#![feature(pointer_is_aligned_to)]

0 commit comments

Comments
 (0)